github.com/zignig/go-ipfs@v0.0.0-20141111235910-c9e5fdf55a52/net/conn/interface.go (about)

     1  package conn
     2  
     3  import (
     4  	peer "github.com/jbenet/go-ipfs/peer"
     5  	u "github.com/jbenet/go-ipfs/util"
     6  	ctxc "github.com/jbenet/go-ipfs/util/ctxcloser"
     7  
     8  	ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
     9  )
    10  
    11  // Map maps Keys (Peer.IDs) to Connections.
    12  type Map map[u.Key]Conn
    13  
    14  // Conn is a generic message-based Peer-to-Peer connection.
    15  type Conn interface {
    16  	// implement ContextCloser too!
    17  	ctxc.ContextCloser
    18  
    19  	// ID is an identifier unique to this connection.
    20  	ID() string
    21  
    22  	// LocalMultiaddr is the Multiaddr on this side
    23  	LocalMultiaddr() ma.Multiaddr
    24  
    25  	// LocalPeer is the Peer on our side of the connection
    26  	LocalPeer() peer.Peer
    27  
    28  	// RemoteMultiaddr is the Multiaddr on the remote side
    29  	RemoteMultiaddr() ma.Multiaddr
    30  
    31  	// RemotePeer is the Peer on the remote side
    32  	RemotePeer() peer.Peer
    33  
    34  	// In returns a readable message channel
    35  	In() <-chan []byte
    36  
    37  	// Out returns a writable message channel
    38  	Out() chan<- []byte
    39  
    40  	// Get an error from this conn if one is available
    41  	// TODO: implement a better error handling system
    42  	GetError() error
    43  }
    44  
    45  // Dialer is an object that can open connections. We could have a "convenience"
    46  // Dial function as before, but it would have many arguments, as dialing is
    47  // no longer simple (need a peerstore, a local peer, a context, a network, etc)
    48  type Dialer struct {
    49  
    50  	// LocalPeer is the identity of the local Peer.
    51  	LocalPeer peer.Peer
    52  
    53  	// Peerstore is the set of peers we know about locally. The Dialer needs it
    54  	// because when an incoming connection is identified, we should reuse the
    55  	// same peer objects (otherwise things get inconsistent).
    56  	Peerstore peer.Peerstore
    57  }
    58  
    59  // Listener is an object that can accept connections. It matches net.Listener
    60  type Listener interface {
    61  
    62  	// Accept waits for and returns the next connection to the listener.
    63  	Accept() <-chan Conn
    64  
    65  	// Multiaddr is the identity of the local Peer.
    66  	Multiaddr() ma.Multiaddr
    67  
    68  	// LocalPeer is the identity of the local Peer.
    69  	LocalPeer() peer.Peer
    70  
    71  	// Peerstore is the set of peers we know about locally. The Listener needs it
    72  	// because when an incoming connection is identified, we should reuse the
    73  	// same peer objects (otherwise things get inconsistent).
    74  	Peerstore() peer.Peerstore
    75  
    76  	// Close closes the listener.
    77  	// Any blocked Accept operations will be unblocked and return errors.
    78  	Close() error
    79  }