network

package
v0.0.0-...-97f3c37 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MAX_REQ_TIME = 20 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ID

type ID []byte
var (
	MAX_ID  ID = []byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
	ZERO_ID ID = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
)

Fixed Identifer space of 160 bits * [Note] this works for hex base ids the identifier is a []byte each entry contains 2 digits TODO make it works for generic id radixes

func (ID) AddOne

func (id ID) AddOne(from int) ID

AddOne adds one starting from a specific digit and carrys up

func (ID) Equal

func (id ID) Equal(a ID) bool

func (ID) InLRXRange

func (id ID) InLRXRange(a, b ID) bool

func (ID) InLXRange

func (id ID) InLXRange(a, b ID) bool

function checks if the id is in left execlusive range id is in the range (a, b]

func (ID) LeftShift

func (id ID) LeftShift() (ID, byte)

func (ID) Less

func (id ID) Less(a ID) bool

checks that id is befor a in the ring

func (ID) MaskLowerWith

func (id ID) MaskLowerWith(x ID, i int) ID

changes the lower i bits of id with the heighest i bits of x

func (ID) String

func (id ID) String() string

func (ID) TopShift

func (id ID) TopShift(a ID) ID

type Node

type Node struct {
	// RPC stuff
	rpc.UnimplementedKoordeServer
	Peer
	D            *Peer
	DParents     []*Peer
	Successor    *Peer
	Predecessor  *Peer
	NodeShutdown chan bool

	// communication
	ChanNetBlock        chan<- data.Block
	ChanNetTransaction  chan<- data.Transaction
	ChanConsBlock       <-chan data.Block
	ChanConsTransaction <-chan data.Transaction
	// contains filtered or unexported fields
}

func New

New() constructs a new network node, and it setups the communication channels with the Consensus Module

func (*Node) AddDParentRPC

func (ln *Node) AddDParentRPC(bctx context.Context, p *rpc.PeerPacket) (*rpc.Empty, error)

func (*Node) BootStarpRPC

func (ln *Node) BootStarpRPC(bctx context.Context, bootstrapPacket *rpc.BootStrapPacket) (*rpc.BootStrapReply, error)

func (*Node) BroadCast

func (ln *Node) BroadCast(thing interface{}) error

func (*Node) BroadCastRPC

func (ln *Node) BroadCastRPC(ctx context.Context, b *rpc.BroadCastPacket) (*rpc.Empty, error)

func (*Node) DGetBlocks

func (n *Node) DGetBlocks(ctx context.Context, e *rpc.Empty) (*rpc.BlocksPacket, error)

func (*Node) DGetID

func (n *Node) DGetID(ctx context.Context, e *rpc.Empty) (*rpc.PeerPacket, error)

func (*Node) DGetPointers

func (n *Node) DGetPointers(ctx context.Context, e *rpc.Empty) (*rpc.Pointers, error)

func (*Node) DJoin

func (n *Node) DJoin(ctx context.Context, p *rpc.PeerPacket) (*rpc.Empty, error)

func (*Node) DLKup

func (n *Node) DLKup(ctx context.Context, p *rpc.PeerPacket) (*rpc.PeerPacket, error)

func (*Node) DSetD

func (n *Node) DSetD(ctx context.Context, p *rpc.PeerPacket) (*rpc.Empty, error)

func (*Node) DSetSuccessor

func (n *Node) DSetSuccessor(ctx context.Context, p *rpc.PeerPacket) (*rpc.Empty, error)

func (*Node) GetPredecessorRPC

func (ln *Node) GetPredecessorRPC(ctx context.Context, e *rpc.Empty) (*rpc.PeerPacket, error)

func (*Node) GetSuccessorRPC

func (ln *Node) GetSuccessorRPC(ctx context.Context, e *rpc.Empty) (*rpc.PeerPacket, error)

func (*Node) Init

func (ln *Node) Init(port int) error

Init initializes the first node in the network It inits the Successor, D pointers with default values (node itslef)

func (*Node) InitBroadCastRPC

func (n *Node) InitBroadCastRPC(ctx context.Context, b *rpc.BroadCastPacket) (*rpc.Empty, error)

func (*Node) Join

func (ln *Node) Join(nodeAddr *net.TCPAddr, port int) error

Join initializes the node by executing Chord Join Algorithm It inits the Successor, D pointers

func (*Node) Lookup

func (ln *Node) Lookup(k ID) (*Peer, error)

func (*Node) LookupRPC

func (ln *Node) LookupRPC(bctx context.Context, lookupPacket *rpc.LookupPacket) (*rpc.PeerPacket, error)

func (*Node) NotifyRPC

func (ln *Node) NotifyRPC(ctx context.Context, p *rpc.PeerPacket) (*rpc.Empty, error)

func (*Node) RemoveDParentRPC

func (ln *Node) RemoveDParentRPC(btcx context.Context, p *rpc.PeerPacket) (*rpc.Empty, error)

func (*Node) UrpcateDPointerRPC

func (ln *Node) UrpcateDPointerRPC(bctx context.Context, p *rpc.PeerPacket) (*rpc.Empty, error)

func (*Node) UrpcatePredecessorRPC

func (ln *Node) UrpcatePredecessorRPC(bctx context.Context, p *rpc.PeerPacket) (*rpc.PeerPacket, error)

func (*Node) UrpcateSuccessorRPC

func (ln *Node) UrpcateSuccessorRPC(bctx context.Context, p *rpc.PeerListPacket) (*rpc.PeerListPacket, error)

type Peer

type Peer struct {
	NetAddr  *net.TCPAddr
	NodeAddr ID
	Start    ID
	Interval []ID
	// contains filtered or unexported fields
}

func (*Peer) CloseConnection

func (p *Peer) CloseConnection()

func (*Peer) InitConnection

func (p *Peer) InitConnection() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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