node

package
v0.0.0-...-3431805 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dinstance

func Dinstance(node1, node2 *Node) (*big.Int, error)

func GenerateAddressFromNode

func GenerateAddressFromNode(node *Node) (net.Addr, error)

func ReadIntoStream

func ReadIntoStream(conn io.Reader) ([]byte, error)

Types

type Codec

type Codec interface {
	Serialize(msg *message) ([]byte, error)
	Deserialize(bytestream []byte) (*message, error)
}

func NewCodec

func NewCodec() Codec

type CodecImp

type CodecImp struct{} //Possibly add some state later

func (*CodecImp) Deserialize

func (codec *CodecImp) Deserialize(bytestream []byte) (*message, error)

func (*CodecImp) Serialize

func (codec *CodecImp) Serialize(msg *message) ([]byte, error)

type LocalNode

type LocalNode struct {
	*Node
	*RoutingTable
	Codec
	RpcChan chan *message
	// contains filtered or unexported fields
}

This is the representation of the local node on the network

func NewLocalNode

func NewLocalNode(node *Node) (*LocalNode, error)

func (*LocalNode) FindNode

func (node *LocalNode) FindNode(cid [20]byte) ([]Node, error)

func (*LocalNode) FindValue

func (node *LocalNode) FindValue(cid [20]byte) ([]byte, error)

func (*LocalNode) GenerateRpcReply

func (node *LocalNode) GenerateRpcReply(stream []byte) (*message, error)

func (*LocalNode) GenerateRpcRequest

func (node *LocalNode) GenerateRpcRequest(RpcType int) (*message, error)

func (*LocalNode) Ping

func (node *LocalNode) Ping(n *Node) (bool, error)

func (*LocalNode) Send

func (node *LocalNode) Send(msg *message, connection net.PacketConn) error

func (*LocalNode) Server

func (node *LocalNode) Server(ErrChan chan error)

func (*LocalNode) Store

func (node *LocalNode) Store(cid [20]byte, value []byte) error

type Node

type Node struct {
	Cid  [b / 8]byte
	IP   net.IP
	Port int
}

This is the representation of a remote node on the network

func NewNode

func NewNode(ip string, port string) (*Node, error)

type RoutingTable

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

func NewRoutingTable

func NewRoutingTable(localnode *LocalNode) (*RoutingTable, error)

Creates a new routing table

func (*RoutingTable) Dinstance

func (r *RoutingTable) Dinstance(node *Node) (*big.Int, error)

Returns the dinstance between the input node and the node that owns the routing table

func (*RoutingTable) InsertNode

func (r *RoutingTable) InsertNode(node *Node) (int, error)

Inserts a node to the routing table according to kademlia specifications

Jump to

Keyboard shortcuts

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