github.com/keltia/go-ipfs@v0.3.8-0.20150909044612-210793031c63/p2p/net/conn/interface.go (about) 1 package conn 2 3 import ( 4 "io" 5 "net" 6 "time" 7 8 key "github.com/ipfs/go-ipfs/blocks/key" 9 ic "github.com/ipfs/go-ipfs/p2p/crypto" 10 filter "github.com/ipfs/go-ipfs/p2p/net/filter" 11 peer "github.com/ipfs/go-ipfs/p2p/peer" 12 13 msgio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-msgio" 14 ma "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr" 15 manet "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net" 16 ) 17 18 // Map maps Keys (Peer.IDs) to Connections. 19 type Map map[key.Key]Conn 20 21 type PeerConn interface { 22 io.Closer 23 24 // LocalPeer (this side) ID, PrivateKey, and Address 25 LocalPeer() peer.ID 26 LocalPrivateKey() ic.PrivKey 27 LocalMultiaddr() ma.Multiaddr 28 29 // RemotePeer ID, PublicKey, and Address 30 RemotePeer() peer.ID 31 RemotePublicKey() ic.PubKey 32 RemoteMultiaddr() ma.Multiaddr 33 } 34 35 // Conn is a generic message-based Peer-to-Peer connection. 36 type Conn interface { 37 PeerConn 38 39 // ID is an identifier unique to this connection. 40 ID() string 41 42 // can't just say "net.Conn" cause we have duplicate methods. 43 LocalAddr() net.Addr 44 RemoteAddr() net.Addr 45 SetDeadline(t time.Time) error 46 SetReadDeadline(t time.Time) error 47 SetWriteDeadline(t time.Time) error 48 49 msgio.Reader 50 msgio.Writer 51 } 52 53 // Dialer is an object that can open connections. We could have a "convenience" 54 // Dial function as before, but it would have many arguments, as dialing is 55 // no longer simple (need a peerstore, a local peer, a context, a network, etc) 56 type Dialer struct { 57 58 // Dialer is an optional manet.Dialer to use. 59 Dialer manet.Dialer 60 61 // LocalPeer is the identity of the local Peer. 62 LocalPeer peer.ID 63 64 // LocalAddrs is a set of local addresses to use. 65 LocalAddrs []ma.Multiaddr 66 67 // PrivateKey used to initialize a secure connection. 68 // Warning: if PrivateKey is nil, connection will not be secured. 69 PrivateKey ic.PrivKey 70 71 // Wrapper to wrap the raw connection (optional) 72 Wrapper func(manet.Conn) manet.Conn 73 } 74 75 // Listener is an object that can accept connections. It matches net.Listener 76 type Listener interface { 77 78 // Accept waits for and returns the next connection to the listener. 79 Accept() (net.Conn, error) 80 81 // Addr is the local address 82 Addr() net.Addr 83 84 // Multiaddr is the local multiaddr address 85 Multiaddr() ma.Multiaddr 86 87 // LocalPeer is the identity of the local Peer. 88 LocalPeer() peer.ID 89 90 SetAddrFilters(*filter.Filters) 91 92 // Close closes the listener. 93 // Any blocked Accept operations will be unblocked and return errors. 94 Close() error 95 } 96 97 // EncryptConnections is a global parameter because it should either be 98 // enabled or _completely disabled_. I.e. a node should only be able to talk 99 // to proper (encrypted) networks if it is encrypting all its transports. 100 // Running a node with disabled transport encryption is useful to debug the 101 // protocols, achieve implementation interop, or for private networks which 102 // -- for whatever reason -- _must_ run unencrypted. 103 var EncryptConnections = true