pubsubPlebbitValidator

package module
v0.0.0-...-36dfdea Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2023 License: GPL-2.0 Imports: 17 Imported by: 0

README

Usage

import (
    libp2p "github.com/libp2p/go-libp2p"
    pubsub "github.com/libp2p/go-libp2p-pubsub"
    plebbitValidator "github.com/plebbit/go-libp2p-pubsub-plebbit-validator"
)

func main() {
    // create libp2p
    host, err := libp2p.New(libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0"))
    if err != nil {
        panic(err)
    }

    // create pubsub with plebbit validator
    ctx := context.Background()
    ps, err := pubsub.NewGossipSub(ctx, host, pubsub.WithDefaultValidator(plebbitValidator.validate))
    if err != nil {
        panic(err)
    }

    // create test pubsub topic
    topic, err := ps.Join("test-topic")
    if err != nil {
        panic(err)
    }

    message := []byte("hello")
    topic.Publish(ctx, message)
}

Test

go test

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PeerScoreParams pubsub.PeerScoreParams = pubsub.PeerScoreParams{
	AppSpecificScore: func(p peer.ID) float64 {
		return 0
	},
	AppSpecificWeight: 1,

	IPColocationFactorThreshold: 5,
	IPColocationFactorWeight:    -100,
	IPColocationFactorWhitelist: []*net.IPNet{},

	BehaviourPenaltyThreshold: 6,
	BehaviourPenaltyWeight:    -10,
	BehaviourPenaltyDecay:     pubsub.ScoreParameterDecay(time.Hour),

	DecayInterval: pubsub.DefaultDecayInterval,
	DecayToZero:   pubsub.DefaultDecayToZero,

	RetainScore: 6 * time.Hour,

	Topics: map[string]*pubsub.TopicScoreParams{},
}

values copied from https://github.com/filecoin-project/lotus/blob/42d2f4d7e48104c4b8c6f19720e4eef369976442/node/modules/lp2p/pubsub.go

View Source
var PeerScoreThresholds pubsub.PeerScoreThresholds = pubsub.PeerScoreThresholds{
	GossipThreshold:             -500,
	PublishThreshold:            -1000,
	GraylistThreshold:           -2500,
	AcceptPXThreshold:           1000,
	OpportunisticGraftThreshold: 3.5,
}

values copied from https://github.com/filecoin-project/lotus/blob/42d2f4d7e48104c4b8c6f19720e4eef369976442/node/modules/lp2p/pubsub.go

Functions

func NewPeerScoreParams

func NewPeerScoreParams(validator Validator) pubsub.PeerScoreParams

Types

type PeerStatistics

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

type Signature

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

type Validator

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

func NewValidator

func NewValidator(host host.Host) Validator

func (Validator) AppSpecificScore

func (validator Validator) AppSpecificScore(peerId peer.ID) float64

func (Validator) Validate

func (validator Validator) Validate(ctx context.Context, peerId peer.ID, pubsubMessage *pubsub.Message) bool

Jump to

Keyboard shortcuts

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