host

package
v0.0.0-...-307e7aa Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0, MIT Imports: 28 Imported by: 2

Documentation

Index

Constants

View Source
const PeerScoreEventType = "PEERSCORE"

Variables

This section is empty.

Functions

func MaddrFrom

func MaddrFrom(ip string, port uint) (ma.Multiaddr, error)

MaddrFrom takes in an ip address string and port to produce a go multiaddr format.

func NoopHandler

func NoopHandler(ctx context.Context, msg *pubsub.Message) error

Types

type Config

type Config struct {
	DataStream            DataStream
	PeerscoreSnapshotFreq time.Duration

	// Telemetry accessors
	Tracer trace.Tracer
	Meter  metric.Meter
}

type DataStream

type DataStream interface {
	Start(ctx context.Context) error
	PutRecord(ctx context.Context, record gk.Record) error
}

type Host

type Host struct {
	host.Host
	// contains filtered or unexported fields
}

func New

func New(cfg *Config, opts ...libp2p.Option) (*Host, error)

func (*Host) AddPeer

func (h *Host) AddPeer(p peer.ID, proto protocol.ID)

func (*Host) AgentVersion

func (h *Host) AgentVersion(pid peer.ID) string

AgentVersion returns the agent version of the given peer. If the agent version is not known, it returns an empty string.

func (*Host) ConnSignal

func (h *Host) ConnSignal(ctx context.Context, pid peer.ID) chan error

ConnSignal signals the incoming connection of the given peer on the returned channel by just closing it. Alternatively, if the context has a deadline that's exceeded, the channel will emit the context error and then be closed.

func (*Host) DeliverMessage

func (h *Host) DeliverMessage(msg *pubsub.Message)

func (*Host) DropRPC

func (h *Host) DropRPC(rpc *pubsub.RPC, p peer.ID)

func (*Host) DuplicateMessage

func (h *Host) DuplicateMessage(msg *pubsub.Message)

func (*Host) FlushTrace

func (h *Host) FlushTrace(evtType string, payload any)

func (*Host) FlushTraceWithTimestamp

func (h *Host) FlushTraceWithTimestamp(evtType string, timestamp time.Time, payload any)

func (*Host) Graft

func (h *Host) Graft(p peer.ID, topic string)

func (*Host) InitGossipSub

func (h *Host) InitGossipSub(ctx context.Context, opts ...pubsub.Option) (*pubsub.PubSub, error)

func (*Host) Join

func (h *Host) Join(topic string)

func (*Host) Leave

func (h *Host) Leave(topic string)

func (*Host) PrivateListenMaddr

func (h *Host) PrivateListenMaddr() (ma.Multiaddr, error)

PrivateListenMaddr returns the first multiaddress in a private IP range that this host is listening on.

func (*Host) Prune

func (h *Host) Prune(p peer.ID, topic string)

func (*Host) RecvRPC

func (h *Host) RecvRPC(rpc *pubsub.RPC)

func (*Host) RejectMessage

func (h *Host) RejectMessage(msg *pubsub.Message, reason string)

func (*Host) RemovePeer

func (h *Host) RemovePeer(p peer.ID)

func (*Host) SendRPC

func (h *Host) SendRPC(rpc *pubsub.RPC, p peer.ID)

func (*Host) Serve

func (h *Host) Serve(ctx context.Context) error

func (*Host) ThrottlePeer

func (h *Host) ThrottlePeer(p peer.ID)

func (*Host) Trace

func (h *Host) Trace(evt *pubsubpb.TraceEvent)

func (*Host) TracedTopicHandler

func (h *Host) TracedTopicHandler(handler TopicHandler) TopicHandler

func (*Host) UndeliverableMessage

func (h *Host) UndeliverableMessage(msg *pubsub.Message)

func (*Host) UpdatePeerScore

func (h *Host) UpdatePeerScore(scores map[peer.ID]*pubsub.PeerScoreSnapshot)

func (*Host) ValidateMessage

func (h *Host) ValidateMessage(msg *pubsub.Message)

func (*Host) WaitForPublicAddress

func (h *Host) WaitForPublicAddress(ctx context.Context) error

WaitForPublicAddress blocks until the libp2p host has identified its own addresses at which its publicly reachable.

type NoopDataStream

type NoopDataStream struct{}

func (NoopDataStream) PutRecord

func (n NoopDataStream) PutRecord(ctx context.Context, record gk.Record) error

func (NoopDataStream) Start

func (n NoopDataStream) Start(ctx context.Context) error

type ScoreKeeper

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

ScoreKeeper is a thread-safe local copy of the score per peer and per copy TODO: figure out if this is some sort of info that we want to expose through OpenTelemetry (Still good to have it)

func (*ScoreKeeper) Get

func (sk *ScoreKeeper) Get() map[peer.ID]*pubsub.PeerScoreSnapshot

func (*ScoreKeeper) Update

func (sk *ScoreKeeper) Update(scores map[peer.ID]*pubsub.PeerScoreSnapshot)

type TopicHandler

type TopicHandler = func(context.Context, *pubsub.Message) error

type TopicScore

type TopicScore struct {
	Topic                    string
	TimeInMesh               time.Duration
	FirstMessageDeliveries   float64
	MeshMessageDeliveries    float64
	InvalidMessageDeliveries float64
}

type TopicSubscription

type TopicSubscription struct {
	Topic   string
	LocalID peer.ID
	Sub     *pubsub.Subscription
	Handler TopicHandler
}

func (*TopicSubscription) Serve

func (t *TopicSubscription) Serve(ctx context.Context) error

type TraceEvent

type TraceEvent struct {
	Type      string
	PeerID    peer.ID
	Timestamp time.Time
	Payload   any `json:"Data"` // cannot use field "Data" because of gk.Record method
}

func (*TraceEvent) Data

func (t *TraceEvent) Data() []byte

func (*TraceEvent) ExplicitHashKey

func (t *TraceEvent) ExplicitHashKey() *string

func (*TraceEvent) PartitionKey

func (t *TraceEvent) PartitionKey() string

type TraceEventPeerScore

type TraceEventPeerScore struct {
	PeerID             string
	Score              float64
	AppSpecificScore   float64
	IPColocationFactor float64
	BehaviourPenalty   float64
	Topics             []TopicScore
}

Jump to

Keyboard shortcuts

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