github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/network/p2p/unicast/stream/plain.go (about) 1 package stream 2 3 import ( 4 libp2pnet "github.com/libp2p/go-libp2p/core/network" 5 "github.com/libp2p/go-libp2p/core/protocol" 6 ) 7 8 // PlainStream is a stream factory that reflects the same input stream without any modification. 9 type PlainStream struct { 10 handler libp2pnet.StreamHandler 11 protocolId protocol.ID 12 } 13 14 // NewPlainStream creates a new PlainStream. 15 // Args: 16 // - handler: the stream handler that handles the input stream. 17 // - protocolId: the protocol id of the stream. 18 // Returns: 19 // - PlainStream instance. 20 func NewPlainStream(handler libp2pnet.StreamHandler, protocolId protocol.ID) PlainStream { 21 return PlainStream{ 22 handler: handler, 23 protocolId: protocolId, 24 } 25 } 26 27 // UpgradeRawStream implements protocol interface and returns the input stream without any modification. 28 func (p PlainStream) UpgradeRawStream(s libp2pnet.Stream) (libp2pnet.Stream, error) { 29 return s, nil 30 } 31 32 func (p PlainStream) Handler(s libp2pnet.Stream) { 33 p.handler(s) 34 } 35 36 func (p PlainStream) ProtocolId() protocol.ID { 37 return p.protocolId 38 }