Documentation ¶
Overview ¶
Package transport provides insolar transport interface. It allows to abstract our insolar from physical transport. It can either be IP based insolar or any other kind of message courier (e.g. an industrial message bus).
Package exports simple interfaces for easily defining new transports.
For now we provide one default implementation using BitTorrent µTP protocol.
Usage:
var conn net.PacketConn // get udp connection anywhere tp, _ := transport.NewUTPTransport(conn) msg := &message.Message{} // Send the async queries and wait for a future future, err := tp.SendRequest(msg) if err != nil { panic(err) } select { case response := <-future.Result(): // Channel was closed if response == nil { panic("chanel closed unexpectedly") } // do something with response case <-time.After(1 * time.Second): future.Cancel() }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AtomicLoadAndIncrementUint64 ¶
AtomicLoadAndIncrementUint64 performs CAS loop, increments counter and returns old value.
Types ¶
type CancelCallback ¶
type CancelCallback func(Future)
CancelCallback is a callback function executed when cancelling Future.
type Factory ¶
Factory allows to create new Transport.
func NewUTPTransportFactory ¶
func NewUTPTransportFactory() Factory
NewUTPTransportFactory creates new Factory of utpTransport.
type Future ¶
type Future interface { // ID returns message sequence number. ID() message.RequestID // Actor returns the initiator of the message. Actor() *node.Node // Request returns origin request. Request() *message.Message // Result is a channel to listen for future result. Result() <-chan *message.Message // SetResult makes message to appear in result channel. SetResult(*message.Message) // Cancel closes all channels and cleans up underlying structures. Cancel() }
Future is insolar response future.
type Transport ¶
type Transport interface { // SendRequest sends message to destination. Sequence number is generated automatically. SendRequest(*message.Message) (Future, error) // SendResponse sends message for request with passed request id. SendResponse(message.RequestID, *message.Message) error // Start starts thread to listen incoming messages. Start() error // Stop gracefully stops listening. Stop() // Close disposing all transport underlying structures after stop are called. Close() // Messages returns channel to listen incoming messages. Messages() <-chan *message.Message // Stopped returns signal channel to support graceful shutdown. Stopped() <-chan bool }
Transport is an interface for insolar transport.
func NewUTPTransport ¶
NewUTPTransport creates utpTransport.