hello

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: Apache-2.0, MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const PeerTag = "fcpeer"

PeerTag is the ConnManager tag we apply to peers who pass our Hello genesis check. Worth +10 score so the connmgr trim pass keeps them over random peers we picked up via DHT.

View Source
const PeerTagWeight = 10
View Source
const ProtocolID protocol.ID = "/fil/hello/1.0.0"

ProtocolID is the libp2p protocol ID for Filecoin Hello.

Variables

This section is empty.

Functions

This section is empty.

Types

type HeadProvider

type HeadProvider func() (cids []cid.Cid, height int64, weight string)

HeadProvider returns the current chain head: tipset CIDs, epoch, and parent weight. Lantern's daemon supplies a closure backed by the trusted root + (when set) the header store.

type HelloMessage

type HelloMessage struct {
	HeaviestTipSet       []cid.Cid
	HeaviestTipSetHeight abi.ChainEpoch
	HeaviestTipSetWeight big.Int
	GenesisHash          cid.Cid
}

HelloMessage is the Filecoin /fil/hello/1.0.0 message. Wire format matches Lotus byte-for-byte; the CBOR codec is in cbor_gen.go.

HeaviestTipSet is the sender's current head tipset (one or more block CIDs). HeaviestTipSetHeight is the head epoch. HeaviestTipSetWeight is the cumulative parent weight at that head. GenesisHash is the CID of block 0 (network identity); receivers close the connection on mismatch.

func (*HelloMessage) MarshalCBOR

func (t *HelloMessage) MarshalCBOR(w io.Writer) error

func (*HelloMessage) UnmarshalCBOR

func (t *HelloMessage) UnmarshalCBOR(r io.Reader) (err error)

type LatencyMessage

type LatencyMessage struct {
	TArrival int64
	TSent    int64
}

LatencyMessage is the optional reply sent by Lotus peers carrying their arrival + sent timestamps for clock-skew measurement. Lantern reads it to drain the stream cleanly but doesn't act on it.

func (*LatencyMessage) MarshalCBOR

func (t *LatencyMessage) MarshalCBOR(w io.Writer) error

func (*LatencyMessage) UnmarshalCBOR

func (t *LatencyMessage) UnmarshalCBOR(r io.Reader) (err error)

type Service

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

Service wires the Hello protocol onto a libp2p Host.

func NewService

func NewService(h host.Host, genesis cid.Cid, head HeadProvider) *Service

NewService constructs a Hello service. Caller must call Register to attach the stream handler.

genesis is the canonical genesis CID for this network (mainnet, calibnet). head is a callback that returns the current chain head; Service will call it on every outbound SayHello so the wire message reflects current state.

func (*Service) Register

func (s *Service) Register()

Register attaches the Hello stream handler to the host. Idempotent.

func (*Service) SayHello

func (s *Service) SayHello(ctx context.Context, pid peer.ID) error

SayHello dials the remote peer's Hello protocol and sends our HelloMessage. Idempotent (libp2p multiplexes streams). Bounded by streamOpenTimeout + streamDeadline.

func (*Service) Stats

func (s *Service) Stats() Stats

Stats returns a snapshot of Hello counters.

func (*Service) WatchNewConns

func (s *Service) WatchNewConns(ctx context.Context)

WatchNewConns spawns a goroutine that listens for new outbound libp2p connections and proactively SayHello to each remote. This is the loop that actually keeps peer count up over time: every new peer we dial gets a Hello within the first second, so remote connmgrs score us positively from the start.

Cancellation: stops when ctx is done.

type Stats

type Stats struct {
	Received uint64 `json:"received"`
	Sent     uint64 `json:"sent"`
	Rejected uint64 `json:"rejected"`
}

Stats reports observable Hello activity. Exposed for the dashboard.

Jump to

Keyboard shortcuts

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