router

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2021 License: Apache-2.0 Imports: 21 Imported by: 44

Documentation

Index

Constants

View Source
const (
	PeerTypeMulticast int = iota
	PeerTypeBluetooth
	PeerTypeRemote
)
View Source
const MaxFrameSize = 65535*3 + 12

MaxFrameSize is the maximum size that a single frame can be, including all headers.

View Source
const MaxPayloadSize = 65535

MaxPayloadSize is the maximum size that a single frame can contain as a payload, not including headers.

View Source
const PortCount = 64

PortCount contains the number of ports supported by this Pinecone node. This is, in practice, the limit of concurrent peering connections that are supported at one time.

View Source
const ProtoBufferSize = 16

ProtoBufferSize is the number of protocol packets that a node will buffer on a slow port.

View Source
const TrafficBufferSize = 256

TrafficBufferSize is the number of traffic packets that a node will buffer on a slow port.

Variables

This section is empty.

Functions

This section is empty.

Types

type GreedyAddr

type GreedyAddr struct {
	types.SwitchPorts
}

GreedyAddr implements net.Addr, containing a greedy-routed set of destination coordinates to another node.

func (GreedyAddr) Network

func (a GreedyAddr) Network() string

func (GreedyAddr) String

func (a GreedyAddr) String() string

type Peer

type Peer struct {
	// contains filtered or unexported fields
}

func (*Peer) Coordinates

func (p *Peer) Coordinates() types.SwitchPorts

func (*Peer) PublicKey

func (p *Peer) PublicKey() types.PublicKey

func (*Peer) SeenCommonRootRecently added in v0.2.0

func (p *Peer) SeenCommonRootRecently() bool

func (*Peer) SeenRecently

func (p *Peer) SeenRecently() bool

type PeerInfo

type PeerInfo struct {
	Port          int
	PublicKey     string
	RootPublicKey string
	PeerType      int
	Zone          string
}

PeerInfo is a gomobile-friendly type that represents a peer connection.

type Router

type Router struct {
	// contains filtered or unexported fields
}

Implements net.PacketConn. A Router is an instance of a Pinecone node and should only be instantiated using the NewRouter method.

func NewRouter

func NewRouter(log *log.Logger, id string, private ed25519.PrivateKey, public ed25519.PublicKey, simulator Simulator) *Router

NewRouter instantiates a new Pinecone Router instance. The logger is where all log output will be sent for this node. The ID is a friendly string that identifies the node, but is not used at the protocol level and is not visible outside externally. The private and public keys are the primary identity of the node and therefore must be unique for each node. These keys are also used to sign protocol messages.

func (*Router) Addr

func (r *Router) Addr() net.Addr

Addr returns a net.Addr instance that addresses this node using greedy routing.

func (*Router) AllowImpreciseTraffic added in v0.2.0

func (r *Router) AllowImpreciseTraffic(allow bool)

AllowImpreciseTraffic controls whether the router should return traffic that isn't specifically destined for this node but has nowhere else to go. This is a requirement for routing with partial public keys.

func (*Router) Ascending added in v0.3.0

func (r *Router) Ascending() (*types.PublicKey, *types.VirtualSnakePathID)

DHTSuccessor returns the public key of the next node in the DHT snake.

func (*Router) AuthenticatedConnect

func (r *Router) AuthenticatedConnect(conn net.Conn, zone string, peertype int) (types.SwitchPortID, error)

AuthenticatedConnect initiates a peer connection using the given net.Conn connection. The public keys of the nodes are exchanged using a handshake. The connection will fail if this handshake fails. The port number that the node was connected to will be returned in the event of a successful connection.

func (*Router) Close

func (r *Router) Close() error

Close shuts down the node and stops the peering connections. The node should not be used after this has been called.

func (*Router) Connect

func (r *Router) Connect(conn net.Conn, public types.PublicKey, zone string, peertype int) (types.SwitchPortID, error)

Connect initiates a peer connection using the given net.Conn connection, in the event that the public key of the node is already known (e.g. in the simulator). The port number that the node was connected to will be returned in the event of a successful connection.

func (*Router) Coords

func (r *Router) Coords() types.SwitchPorts

Coords returns the current spanning tree coordinates of this node. The coordinates are effectively a source routing path from the root down to the node.

func (*Router) DHTInfo added in v0.3.0

func (r *Router) DHTInfo() (asc, desc *virtualSnakeNeighbour, table map[virtualSnakeIndex]virtualSnakeEntry)

func (*Router) DHTSearch

func (r *Router) DHTSearch(ctx context.Context, pk ed25519.PublicKey, stopshort bool) (types.PublicKey, net.Addr, error)

DHTSearch initiates a DHT search for the given public key. The stopshort flag, if set to true, will return the closest node to the public key found in the search. If set to false, the search will fail and return an error if the specific node is not found.

func (*Router) Descending added in v0.3.0

func (r *Router) Descending() (*types.PublicKey, *types.VirtualSnakePathID)

DHTPredecessor returns the public key of the previous node in the DHT snake.

func (*Router) Disconnect

func (r *Router) Disconnect(i types.SwitchPortID, err error) error

Disconnect will disconnect whatever is connected to the given port number on the Pinecone node. The peering will no longer be used and the underlying connection will be closed.

func (*Router) IsConnected

func (r *Router) IsConnected(key types.PublicKey, zone string) bool

IsConnected returns true if the node is connected within the given zone, or false otherwise.

func (*Router) IsRoot

func (r *Router) IsRoot() bool

IsRoot returns true if this node believes it is the root of the network. This will likely return true if the node is isolated (e.g. has no peers).

func (*Router) KnownNodes

func (r *Router) KnownNodes() []types.PublicKey

KnownNodes returns a list of all nodes that are known about directly. This includes all peers and all ancestor nodes between this node and the root node.

func (*Router) LocalAddr

func (r *Router) LocalAddr() net.Addr

LocalAddr returns a net.Addr containing the greedy routing coordinates for this node.

func (*Router) ParentPublicKey added in v0.2.0

func (r *Router) ParentPublicKey() types.PublicKey

ParentPublicKey returns the public key of the node that this node believes is the parent.

func (*Router) Pathfind

func (r *Router) Pathfind(ctx context.Context, addr net.Addr) (net.Addr, error)

Pathfind takes a GreedyAddr (for greedy routing) or a types.PublicKey (for snake routing) and performs an active pathfind through the network. A SourceAddr will be returned which can be used to send packets using source routing instead. Note that this generates protocol traffic, so don't call it again unless you are sure the path has changed and the remote host is no longer answering. If the pathfind fails then an error will be returned instead.

func (*Router) PeerCount

func (r *Router) PeerCount(peertype int) int

PeerCount returns the number of nodes that are directly connected to this Pinecone node. This will de-duplicate peerings to the same node in different zones.

func (*Router) Peers

func (r *Router) Peers() []PeerInfo

Peers returns a list of PeerInfos that show all of the currently connected peers.

func (*Router) PrivateKey

func (r *Router) PrivateKey() types.PrivateKey

PrivateKey returns the ed25519 private key in use by this node.

func (*Router) PublicKey

func (r *Router) PublicKey() types.PublicKey

PublicKey returns the ed25519 public key in use by this node.

func (*Router) ReadFrom

func (r *Router) ReadFrom(p []byte) (n int, addr net.Addr, err error)

ReadFrom reads the next packet that was delivered to this node over the Pinecone network. Only traffic packets will be returned here - no protocol messages will be included. The net.Addr returned will contain the appropriate return path based on the mechanism used to deliver the packet. If the packet was delivered using greedy routing, then the net.Addr will contain the source coordinates. If the packet was delivered using source routing, then the net.Addr will contain the source-routed path back to the sender.

func (*Router) RootPublicKey

func (r *Router) RootPublicKey() types.PublicKey

RootPublicKey returns the public key of the node that this node believes is the root of the network.

func (*Router) SetConnectedCallback

func (r *Router) SetConnectedCallback(f func(port types.SwitchPortID, publickey types.PublicKey, peertype int))

SetConnectedCallback defines a function that will be called when a new peer connection is successfully established.

func (*Router) SetDeadline

func (r *Router) SetDeadline(t time.Time) error

SetDeadline is not implemented.

func (*Router) SetDisconnectedCallback

func (r *Router) SetDisconnectedCallback(f func(port types.SwitchPortID, publickey types.PublicKey, peertype int, err error))

SetDisconnectedCallback defines a function that will be called either when an existing peer connection disconnects. An error field contains additional information about why the peering connection was closed.

func (*Router) SetReadDeadline

func (r *Router) SetReadDeadline(t time.Time) error

SetReadDeadline is not implemented.

func (*Router) SetWriteDeadline

func (r *Router) SetWriteDeadline(t time.Time) error

SetWriteDeadline is not implemented.

func (*Router) WriteTo

func (r *Router) WriteTo(p []byte, addr net.Addr) (n int, err error)

WriteTo sends a packet into the Pinecone network. The packet will be sent as a traffic packet. The net.Addr must be one of the Pinecone address types (e.g. GreedyAddr or SourceAddr), as this will dictate the method of delivery used to forward the packet.

type Simulator

type Simulator interface {
	ReportDistance(a, b string, l int64)
	LookupCoords(string) (types.SwitchPorts, error)
	LookupNodeID(types.SwitchPorts) (string, error)
	LookupPublicKey(types.PublicKey) (string, error)
	ReportNewLink(net.Conn, types.PublicKey, types.PublicKey)
	ReportDeadLink(types.PublicKey, types.PublicKey)
}

Simulator is not used by normal Pinecone nodes and specifies the functions that must be satisfied if running under pineconesim.

type SourceAddr

type SourceAddr struct {
	types.SwitchPorts
}

SourceAddr implements net.Addr, containing a source-routed path to another node.

func (SourceAddr) Network

func (a SourceAddr) Network() string

func (SourceAddr) String

func (a SourceAddr) String() string

Jump to

Keyboard shortcuts

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