Documentation ¶
Overview ¶
Package sim provides simple implementations of the principal Kademlia interfaces that allow the construction of simulations and test scenarios. The implementations are not suitable for use with real Kademlia networks.
Index ¶
- Variables
- func AddSchedulers(s Simulator, schedulers ...event.AwareScheduler)
- func RemoveSchedulers(s Simulator, schedulers ...event.AwareScheduler)
- type Endpoint
- func (e *Endpoint[K, A]) AddRequestHandler(protoID address.ProtocolID, req kad.Message, ...) error
- func (e *Endpoint[K, A]) Connectedness(id kad.NodeID[K]) (endpoint.Connectedness, error)
- func (e *Endpoint[K, A]) DialPeer(ctx context.Context, id kad.NodeID[K]) error
- func (e *Endpoint[K, A]) HandleMessage(ctx context.Context, id kad.NodeID[K], protoID address.ProtocolID, ...)
- func (e *Endpoint[K, A]) Key() K
- func (e *Endpoint[K, A]) MaybeAddToPeerstore(ctx context.Context, id kad.NodeInfo[K, A], ttl time.Duration) error
- func (e *Endpoint[K, A]) NetworkAddress(id kad.NodeID[K]) (kad.NodeInfo[K, A], error)
- func (e *Endpoint[K, A]) RemoveRequestHandler(protoID address.ProtocolID)
- func (e *Endpoint[K, A]) SendRequestHandleResponse(ctx context.Context, protoID address.ProtocolID, id kad.NodeID[K], ...) error
- type LiteSimulator
- type Message
- type Router
- type Server
- type ServerConfig
- type SimEndpoint
- type Simulator
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func AddSchedulers ¶
func AddSchedulers(s Simulator, schedulers ...event.AwareScheduler)
AddSchedulers adds a set of schedulers to a simulator
func RemoveSchedulers ¶
func RemoveSchedulers(s Simulator, schedulers ...event.AwareScheduler)
RemoveSchedulers removes a set of schedulers from a simulator
Types ¶
type Endpoint ¶
Endpoint is a single threaded endpoint implementation simulating a network. It simulates a network and handles message exchanges between multiple peers in a simulation.
func NewEndpoint ¶
func (*Endpoint[K, A]) AddRequestHandler ¶
func (e *Endpoint[K, A]) AddRequestHandler(protoID address.ProtocolID, req kad.Message, reqHandler endpoint.RequestHandlerFn[K], ) error
func (*Endpoint[K, A]) Connectedness ¶
Peerstore functions
func (*Endpoint[K, A]) HandleMessage ¶
func (*Endpoint[K, A]) MaybeAddToPeerstore ¶
func (e *Endpoint[K, A]) MaybeAddToPeerstore(ctx context.Context, id kad.NodeInfo[K, A], ttl time.Duration) error
MaybeAddToPeerstore adds the given address to the peerstore. Endpoint doesn't take into account the ttl.
func (*Endpoint[K, A]) NetworkAddress ¶
func (*Endpoint[K, A]) RemoveRequestHandler ¶
func (e *Endpoint[K, A]) RemoveRequestHandler(protoID address.ProtocolID)
type LiteSimulator ¶
type LiteSimulator struct {
// contains filtered or unexported fields
}
func NewLiteSimulator ¶
func NewLiteSimulator(clk *clock.Mock) *LiteSimulator
func (*LiteSimulator) Add ¶
func (s *LiteSimulator) Add(sched event.AwareScheduler)
func (*LiteSimulator) Clock ¶
func (s *LiteSimulator) Clock() *clock.Mock
func (*LiteSimulator) Remove ¶
func (s *LiteSimulator) Remove(sched event.AwareScheduler)
func (*LiteSimulator) Run ¶
func (s *LiteSimulator) Run(ctx context.Context)
type Message ¶
Message is a simple implementation of `Request` and `Response`. It only contains the minimal fields that are required by Kademlia to operate.
func NewResponse ¶
func (*Message[K, A]) CloserNodes ¶
func (*Message[K, A]) EmptyResponse ¶
type ServerConfig ¶
func DefaultServerConfig ¶
func DefaultServerConfig() *ServerConfig
type SimEndpoint ¶
type SimEndpoint[K kad.Key[K], A kad.Address[A]] interface { endpoint.ServerEndpoint[K, A] // HandleMessage handles a message from the given peer. HandleMessage(context.Context, kad.NodeID[K], address.ProtocolID, endpoint.StreamID, kad.Message) }
SimEndpoint is a simulated endpoint that doesn't operate on real network
type Simulator ¶
type Simulator interface { // Add adds a scheduler to the simulator Add(event.AwareScheduler) // Remove removes a scheduler from the simulator Remove(event.AwareScheduler) // Run runs the simulator until there are no more Actions to run Run(context.Context) }
Simulator is an interface for simulating a set of schedulers.