Documentation
¶
Index ¶
Constants ¶
const ( IncomingMessage = 0x1 IncomingStream = 0x2 )
Variables ¶
This section is empty.
Functions ¶
func NOPHandshakeFunc ¶
NOPHandshakeFunc are generally used for testing purposes It is a no-op function - which means it does nothing use case eg- when we want to test the transport layer without actually doing the handshake
Types ¶
type DefaultDecoder ¶
type DefaultDecoder struct{}
type GOBDecoder ¶
type GOBDecoder struct{}
type HandshakeFunc ¶
type Peer ¶
type Peer interface {
Close() error // Close closes the connection between the local node and the remote node
Send([]byte) error // Send sends a message to the remote node
net.Conn // Conn returns the connection between the local node and the remote node
}
Peer is an interface that defines the methods that a peer must implement ( It represents a node in the network )
type TCPPeer ¶
func (*TCPPeer) CloseStream ¶
func (p *TCPPeer) CloseStream()
1. CloseStream ---------------------------//
type TCPTransport ¶
type TCPTransport struct {
TCPTransportOptions
// contains filtered or unexported fields
}
func NewTCPTransport ¶
func NewTCPTransport(options TCPTransportOptions) *TCPTransport
func (*TCPTransport) Addr ¶
func (t *TCPTransport) Addr() string
1. Addr ---------------------------//
func (*TCPTransport) Close ¶
func (t *TCPTransport) Close() error
3. Close ---------------------------//
func (*TCPTransport) Consume ¶
func (t *TCPTransport) Consume() <-chan RPC
2. Consume ---------------------------//
func (*TCPTransport) Dial ¶
func (t *TCPTransport) Dial(address string) error
5. Dial ---------------------------//
func (*TCPTransport) ListenAndAccept ¶
func (t *TCPTransport) ListenAndAccept() error
4. ListenAndAccept ---------------------------//
type TCPTransportOptions ¶
type TCPTransportOptions struct {
ListenAddress string
HandshakeFunc HandshakeFunc // in this project we are using NOPHandshakeFunc does nothing. But if we want to implement the handshake we can implement it by creating a function and passing it here
Decoder Decoder // Decoder is an interface that defines the methods that a decoder must implement
OnPeer func(Peer) error // When new peer is connected, this function does something - here we are doing nothing
}
type Transport ¶
type Transport interface {
Addr() string // Addr returns the address of the local node
Dial(string) error // Dial dials a remote node and returns a peer
ListenAndAccept() error // ListenAndAccept listens for incoming connections and accepts them if they are of the correct protocol may it be TCP, UDP websockets etc
Close() error // Close closes the connection between the local node and the remote node
Consume() <-chan RPC // Consume returns a channel that will be used to receive messages from the network
}
Transport is an interface that defines the methods that a transport must implement Transport is anything that handles communication between the nodes in the network (peers) eg. TCP, UDP, Websockets, etc.