dht

package
v0.0.0-...-8ab0ffd Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRandomCoordinates

func GetRandomCoordinates(dims uint) []float32

func LoadTLSCredentials

func LoadTLSCredentials(ipAddress string) (credentials.TransportCredentials, error)

Get the TLS config

func LoggingUnaryClientInterceptor

func LoggingUnaryClientInterceptor(logger *logrus.Logger) grpc.UnaryClientInterceptor

LoggingUnaryClientInterceptor returns a gRPC client interceptor for logging

func LoggingUnaryServerInterceptor

func LoggingUnaryServerInterceptor(logger *logrus.Logger) grpc.UnaryServerInterceptor

LoggingUnaryServerInterceptor returns a gRPC server interceptor for logging

func NodeInfoToProto

func NodeInfoToProto(nodeInfo topology.NodeInfo) *pb.Node

Helper function to convert NodeInfo to proto message

func SetupNodeTLS

func SetupNodeTLS(bootstrapClient pb.BootstrapServiceClient, ip string, port int) error

Types

type Cache

type Cache struct {
	Cache *lru.LRU[string, []byte]
}

type Node

type Node struct {
	pb.UnimplementedCANNodeServer

	IPAddress string

	Info         *topology.NodeInfo
	RoutingTable *routing.RoutingTable
	NeighInfo    []topology.NodeInfo

	KVStore    *store.MemoryStore
	QueryCache *Cache
	// contains filtered or unexported fields
}

func NewNode

func NewNode() *Node

NewNode This function initializes a new Node instance.

func (*Node) AddNeighbor

func (node *Node) AddNeighbor(ctx context.Context, req *pb.AddNeighborRequest) (*pb.AddNeighborResponse, error)

AddNeighbor handles requests to add a node as a neighbor

func (*Node) CleanupStaleConnections

func (node *Node) CleanupStaleConnections()

func (*Node) Delete

func (node *Node) Delete(ctx context.Context, req *pb.DeleteRequest) (*pb.DeleteResponse, error)

func (*Node) DeleteImplementation

func (node *Node) DeleteImplementation(key string, hashToUse int) error

DeleteImplementation This function is used to delete a key in the DHT.

func (*Node) DetectNodeFailure

func (node *Node) DetectNodeFailure()

DetectNodeFailure is called periodically to check for failed nodes

func (*Node) ElectTakeoverCoordinator

func (node *Node) ElectTakeoverCoordinator(ctx context.Context, req *pb.CoordinatorElectionRequest) (*pb.CoordinatorElectionResponse, error)

ElectTakeoverCoordinator handles election requests for takeover coordinator

func (*Node) Get

func (node *Node) Get(ctx context.Context, req *pb.GetRequest) (*pb.GetResponse, error)

func (*Node) GetHelper

func (node *Node) GetHelper(helperCtx context.Context, key string, hashIdx int) ([]byte, error)

func (*Node) GetImplementation

func (node *Node) GetImplementation(key string, hashToUse int) ([]byte, error)

GetImplementation This function is used to retrieve a value from the DHT. Error if the key does not exist or unable to retrieve the value.

func (*Node) GetInfo

func (node *Node) GetInfo() (string, []float32, []float32)

func (*Node) GetNeighbors

func (node *Node) GetNeighbors(ctx context.Context, req *pb.GetNeighborsRequest) (*pb.GetNeighborsResponse, error)

GetNeighbors handles a request to get all neighbors

func (*Node) GetNewCache

func (node *Node) GetNewCache(size int, ttl time.Duration) *Cache

func (*Node) HandleCrashDetection

func (node *Node) HandleCrashDetection(crashedNodeId string, crashedNodeAddress string)

HandleCrashDetection is called when a neighbor's heartbeat fails

func (*Node) Heartbeat

func (node *Node) Heartbeat(ctx context.Context, req *pb.HeartbeatRequest) (*pb.HeartbeatResponse, error)

func (*Node) HeartbeatRoutine

func (node *Node) HeartbeatRoutine()

func (*Node) InitiateLeave

func (node *Node) InitiateLeave(ctx context.Context, req *pb.LeaveRequest) (*pb.LeaveResponse, error)

InitiateLeave handles a request from a node that wants to leave

func (*Node) Join

func (node *Node) Join(ctx context.Context, req *pb.JoinRequest) (*pb.JoinResponse, error)

func (*Node) JoinImplementation

func (node *Node) JoinImplementation(bootstrapAddr string) error

JoinImplementation queries bootstrap node and sends a join query

func (*Node) LeaveImplementation

func (node *Node) LeaveImplementation() error

LeaveImplementation handles the graceful leaving of a node from the CAN network

func (*Node) NotifyAllNeighboursOfTwoHopInfo

func (node *Node) NotifyAllNeighboursOfTwoHopInfo()

NotifyAllNeighboursOfTwoHopInfo notifies all neighbours about the 2-hop information

func (*Node) NotifyNeighbors

func (node *Node) NotifyNeighbors() error

NotifyNeighbors notifies all neighbors about this node

func (*Node) NotifyZoneMerge

func (node *Node) NotifyZoneMerge(ctx context.Context, notification *pb.ZoneMergeNotification) (*pb.ZoneMergeResponse, error)

NotifyZoneMerge handles a notification about a zone merge

func (*Node) PerformDFS

func (node *Node) PerformDFS(ctx context.Context, req *pb.DFSRequest) (*pb.DFSResponse, error)

PerformDFS handles a DFS request from another node

func (*Node) Put

func (node *Node) Put(ctx context.Context, req *pb.PutRequest) (*pb.PutResponse, error)

func (*Node) PutImplementation

func (node *Node) PutImplementation(key string, value []byte, hashToUse int) error

PutImplementation This function is used to store a value in the DHT. Overwrites the value if the key already exists.

func (*Node) SendNeighbourInfo

func (node *Node) SendNeighbourInfo(ctx context.Context, req *pb.NeighbourInfoRequest) (*pb.NeighbourInfoResponse, error)

func (*Node) StartCrashDetection

func (node *Node) StartCrashDetection()

StartCrashDetection starts a goroutine for detecting node failures

func (*Node) StartGRPCServer

func (node *Node) StartGRPCServer(ip string, port int, bootstrapAddr string) error

func (*Node) TakeoverZone

func (node *Node) TakeoverZone(ctx context.Context, req *pb.TakeoverRequest) (*pb.TakeoverResponse, error)

TakeoverZone handles a request to take over another node's zone

func (*Node) TransferData

func (node *Node) TransferData(ctx context.Context, req *pb.TransferDataRequest) (*pb.TransferDataResponse, error)

TransferData handles a request to transfer all data to another node

Jump to

Keyboard shortcuts

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