mirror of
https://github.com/luxfi/node.git
synced 2026-10-30 15:24:05 +00:00
Two packages were named for the same word and meant different things. network/ dialed peers, exchanged keys, throttled and tracked them; nets/ tracked which chains share a validator set and when they have all bootstrapped. One letter apart, and neither name said which was which. The peer layer is mesh — the word this estate already uses for it, in lux-rs/node's own mesh.rs. That frees network for the thing that is actually a network: a set of chains sharing a validator set. A network holds chains; a chain belongs to one network. github.com/luxfi/p2p stays what it is, the gossip library the VMs use. Three concerns, three names, none of them borrowed from another. Co-authored-by: Hanzo Dev <[email protected]>
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package mesh
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/luxfi/ids"
|
|
"github.com/luxfi/node/message"
|
|
"github.com/luxfi/node/version"
|
|
)
|
|
|
|
var _ ExternalHandler = (*testHandler)(nil)
|
|
|
|
// networkInboundHandler is the interface that testHandler needs to implement
|
|
type networkInboundHandler interface {
|
|
HandleInbound(ctx context.Context, msg message.InboundMessage)
|
|
}
|
|
|
|
type testHandler struct {
|
|
networkInboundHandler
|
|
ConnectedF func(nodeID ids.NodeID, nodeVersion *version.Application, netID ids.ID)
|
|
DisconnectedF func(nodeID ids.NodeID)
|
|
HandleGossipF func(ctx context.Context, nodeID ids.NodeID, msg []byte)
|
|
}
|
|
|
|
// HandleInbound handles network message.InboundMessage
|
|
func (h *testHandler) HandleInbound(ctx context.Context, msg message.InboundMessage) {
|
|
// Forward to embedded handler if present
|
|
if h.networkInboundHandler != nil {
|
|
h.networkInboundHandler.HandleInbound(ctx, msg)
|
|
}
|
|
}
|
|
|
|
func (h *testHandler) Connected(id ids.NodeID, nodeVersion *version.Application, netID ids.ID) {
|
|
if h.ConnectedF != nil {
|
|
h.ConnectedF(id, nodeVersion, netID)
|
|
}
|
|
}
|
|
|
|
func (h *testHandler) Disconnected(id ids.NodeID) {
|
|
if h.DisconnectedF != nil {
|
|
h.DisconnectedF(id)
|
|
}
|
|
}
|
|
|
|
func (h *testHandler) HandleGossip(ctx context.Context, nodeID ids.NodeID, msg []byte) {
|
|
if h.HandleGossipF != nil {
|
|
h.HandleGossipF(ctx, nodeID, msg)
|
|
}
|
|
}
|
|
|
|
func (h *testHandler) HandleTimeout(ctx context.Context) {
|
|
// No-op for tests
|
|
}
|