net

package
v0.0.0-...-6206b6d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2021 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientMsgWrapper

type ClientMsgWrapper struct {
	Msg       interface{}
	Timestamp hlc.Timestamp
	C         chan interface{} // reply channel created by request receiver
}

generic client protocol msg with HLC

func (*ClientMsgWrapper) Reply

func (c *ClientMsgWrapper) Reply(reply interface{})

Reply replies to current client session

func (*ClientMsgWrapper) SetReplier

func (c *ClientMsgWrapper) SetReplier(encoder *gob.Encoder)

func (ClientMsgWrapper) String

func (c ClientMsgWrapper) String() string

type Codec

type Codec interface {
	Scheme() string
	Encode(interface{})
	Decode(interface{})
}

Codec interface provide methods for serialization and deserialization combines json and gob encoder decoder interface

func NewCodec

func NewCodec(scheme string, rw io.ReadWriter) Codec

NewCodec creates new codec object based on scheme, i.e. json and gob

type Communication

type Communication interface {
	AddAddress(id idservice.ID, addr string)

	GetAddresses() map[idservice.ID]string

	GetKnownIDs() []idservice.ID

	// Send put message to outbound queue
	Send(to idservice.ID, m interface{}) error

	// MulticastZone send msg to all nodes in the same site
	MulticastZone(zone int, m interface{})

	// MulticastQuorum sends msg to random number of nodes
	MulticastQuorum(quorum int, m interface{})

	// Broadcast send to all peers
	Broadcast(m interface{})

	// BroadcastOneDifferent sends m1 to one random peer, and m2 to the rest
	BroadcastOneDifferent(m1 interface{}, m2 interface{})

	// Recv receives a message
	Recv() interface{}

	Close()

	// Fault injection
	Drop(id idservice.ID, t int)             // drops every message send to NodeId last for t seconds
	Slow(id idservice.ID, d int, t int)      // delays every message send to NodeId for d ms and last for t seconds
	Flaky(id idservice.ID, p float64, t int) // drop message by chance p for t seconds
	Crash(t int)                             // node crash for t seconds
}

Communication integrates all networking interface and fault injections

func NewClientCommunicator

func NewClientCommunicator(addrs map[idservice.ID]string) Communication

NewCommunicator return Communication interface instance given self NodeId, node list, transportLink and codec name

func NewCommunicator

func NewCommunicator(nodeId idservice.ID, addrs map[idservice.ID]string) Communication

NewCommunicator return Communication interface instance given self NodeId, node list, transportLink and codec name

type HandshakeMsg

type HandshakeMsg struct {
	IsClient bool // whether this is a client connecting, if not we should have a NodeId
	NodeId   idservice.ID
}

Initial Handshake

func (HandshakeMsg) String

func (h HandshakeMsg) String() string

type ProtocolMsg

type ProtocolMsg struct {
	HlcTime int64
	MsgId   int64
	Msg     interface{}
}

generic protocol msg with HLC

func (ProtocolMsg) String

func (p ProtocolMsg) String() string

type Read

type Read struct {
	CommandID int
	Key       db.Key
}

Read can be used as a special request that directly read the value of key without go through replication protocol in Replica

func (Read) String

func (r Read) String() string

type ReadReply

type ReadReply struct {
	CommandID int
	Value     db.Value
}

ReadReply cid and value of reading key

func (ReadReply) String

func (r ReadReply) String() string

type Reply

type Reply struct {
	Command    db.Command
	Value      db.Value
	NodeID     idservice.ID
	Properties map[string]string
	Timestamp  int64
	HasErr     bool
	ErrStr     string
}

func (Reply) String

func (r Reply) String() string

type Request

type Request struct {
	Command    db.Command        // Commands for the request
	Properties map[string]string // any additional metadata
	Timestamp  int64
	NodeID     idservice.ID // forward by node. This means the request is not directly from client and is forwarded
}

Request is client request with http response channel

func (Request) String

func (r Request) String() string
type TransportLink interface {
	// Scheme returns transportLink scheme
	Scheme() string

	// Mode returns whether this transportLink is a listener of a dialer
	Mode() TransportMode

	// Send sends message into t.send chan
	Send(interface{})

	// Recv waits for message from t.recv chan
	Recv() interface{}

	// Dial connects to remote server non-blocking once connected
	Dial() error

	// StartOutgoing starts sending any messages in outbound channel on an existing connection
	StartOutgoing(conn net.Conn)

	// Starts handling incoming messages from the remote endpoint
	StartIncoming(conn net.Conn, tm TransportLinkManager)

	// Listen waits for connections, non-blocking once listener starts
	Listen(tm TransportLinkManager)

	// Close closes send channel and stops listener
	Close()
}

TransportLink = client & server

func NewTransportLink(endpointAddr string, nodeId idservice.ID, isClientTransport bool) TransportLink

NewTransportLink creates new transportLink object with end point url, this node's NodeId and client flag for transports that dial to remote server, endpoint is address of the remote server for transports that listen for incoming connection, endpointAddr does not matter nodeId is this node isClientTransport should be set to true if this transportLink is on the client side and there is no nodeId

func NewTransportLinkByNodeId

func NewTransportLinkByNodeId(endpointNodeId idservice.ID, thisNodeId idservice.ID, isClientTransport bool) TransportLink

type TransportLinkManager

type TransportLinkManager interface {
	// Adds transportLink to an existing pool of all transports
	AddTransportLink(t TransportLink, to idservice.ID)
}

type TransportMode

type TransportMode int
const (
	ModeNone     TransportMode = iota
	ModeListener               // for server that listens for connections
	ModeDialer                 // for client that dials the server
	ModeClosed
)

func (TransportMode) String

func (m TransportMode) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL