github.com/aergoio/aergo@v1.3.1/p2p/p2pcommon/transport.go (about) 1 /* 2 * @file 3 * @copyright defined in aergo/LICENSE.txt 4 */ 5 6 package p2pcommon 7 8 import ( 9 "github.com/aergoio/aergo/types" 10 "github.com/libp2p/go-libp2p-core" 11 "github.com/libp2p/go-libp2p-core/network" 12 "time" 13 ) 14 15 16 //go:generate sh -c "mockgen github.com/aergoio/aergo/p2p/p2pcommon NTContainer,NetworkTransport | sed -e 's/^package mock_p2pcommon/package p2pmock/g' > ../p2pmock/mock_networktransport.go" 17 // NTContainer can provide NetworkTransport interface. 18 type NTContainer interface { 19 GetNetworkTransport() NetworkTransport 20 21 // ChainID return id of current chain. 22 ChainID() *types.ChainID 23 SelfMeta() PeerMeta 24 } 25 26 // NetworkTransport do manager network connection 27 // TODO need refactoring. it has other role, pk management of self peer 28 type NetworkTransport interface { 29 core.Host 30 Start() error 31 Stop() error 32 33 SelfMeta() PeerMeta 34 35 GetAddressesOfPeer(peerID types.PeerID) []string 36 37 // AddStreamHandler wrapper function which call host.SetStreamHandler after transport is initialized, this method is for preventing nil error. 38 AddStreamHandler(pid core.ProtocolID, handler network.StreamHandler) 39 40 GetOrCreateStream(meta PeerMeta, protocolIDs ...core.ProtocolID) (core.Stream, error) 41 GetOrCreateStreamWithTTL(meta PeerMeta, ttl time.Duration, protocolIDs ...core.ProtocolID) (core.Stream, error) 42 43 FindPeer(peerID types.PeerID) bool 44 ClosePeerConnection(peerID types.PeerID) bool 45 } 46