stream.go 753 Bytes
Newer Older
1 2 3
package network

import (
tavit ohanian's avatar
tavit ohanian committed
4 5
	"gitlab.dms3.io/p2p/go-p2p-core/mux"
	"gitlab.dms3.io/p2p/go-p2p-core/protocol"
6 7 8
)

// Stream represents a bidirectional channel between two agents in
tavit ohanian's avatar
tavit ohanian committed
9
// a p2p network. "agent" is as granular as desired, potentially
10 11 12 13 14 15
// being a "request -> reply" pair, or whole protocols.
//
// Streams are backed by a multiplexer underneath the hood.
type Stream interface {
	mux.MuxedStream

16 17 18 19
	// ID returns an identifier that uniquely identifies this Stream within this
	// host, during this run. Stream IDs may repeat across restarts.
	ID() string

20 21 22 23 24 25 26 27 28
	Protocol() protocol.ID
	SetProtocol(id protocol.ID)

	// Stat returns metadata pertaining to this stream.
	Stat() Stat

	// Conn returns the connection this stream is part of.
	Conn() Conn
}