p2p

package
v0.0.0-...-348f794 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Msg_Type_name = map[int32]string{
		0: "Hello",
		1: "Miner",
	}
	Msg_Type_value = map[string]int32{
		"Hello": 0,
		"Miner": 1,
	}
)

Enum value maps for Msg_Type.

View Source
var File_message_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type Discovery

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

func NewDiscovery

func NewDiscovery(h host.Host, peer chan peer.AddrInfo) (*Discovery, error)

func (*Discovery) Close

func (d *Discovery) Close() error

func (*Discovery) HandlePeerFound

func (d *Discovery) HandlePeerFound(pa peer.AddrInfo)

type Handler

type Handler struct {
}

func NewHandler

func NewHandler() *Handler

func (*Handler) Close

func (h *Handler) Close() error

func (*Handler) StreamHandler

func (h *Handler) StreamHandler(s network.Stream)

type Hello

type Hello struct {
	Address *string `protobuf:"bytes,1,req,name=address" json:"address,omitempty"`
	// contains filtered or unexported fields
}

func (*Hello) Descriptor deprecated

func (*Hello) Descriptor() ([]byte, []int)

Deprecated: Use Hello.ProtoReflect.Descriptor instead.

func (*Hello) GetAddress

func (x *Hello) GetAddress() string

func (*Hello) ProtoMessage

func (*Hello) ProtoMessage()

func (*Hello) ProtoReflect

func (x *Hello) ProtoReflect() protoreflect.Message

func (*Hello) Reset

func (x *Hello) Reset()

func (*Hello) String

func (x *Hello) String() string

type LibP2p

type LibP2p struct {
	Messages chan *Msg

	Listener *Listener
	// contains filtered or unexported fields
}

func NewLibP2p

func NewLibP2p(cfg *P2pConfig) (*LibP2p, error)

func (*LibP2p) AddPeer

func (p *LibP2p) AddPeer(addr string) error

func (*LibP2p) Broadcast

func (p *LibP2p) Broadcast(msg *Msg) error

func (*LibP2p) Close

func (p *LibP2p) Close() error

func (*LibP2p) MsgChan

func (p *LibP2p) MsgChan() <-chan *Msg

func (*LibP2p) Run

func (p *LibP2p) Run()

func (*LibP2p) SayHello

func (p *LibP2p) SayHello(addr string) error

type Listener

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

func NewListener

func NewListener() *Listener

func (*Listener) AddDisConn

func (l *Listener) AddDisConn(peer peer.ID, addr multiaddr.Multiaddr)

func (*Listener) CanConn

func (l *Listener) CanConn() bool

func (*Listener) Connected

func (l *Listener) Connected(n network.Network, conn network.Conn)

func (*Listener) Disconnected

func (l *Listener) Disconnected(n network.Network, conn network.Conn)

func (*Listener) Listen

func (l *Listener) Listen(n network.Network, multiaddr multiaddr.Multiaddr)

func (*Listener) ListenClose

func (l *Listener) ListenClose(n network.Network, multiaddr multiaddr.Multiaddr)

type Miner

type Miner struct {
	MinerAddr *string `protobuf:"bytes,2,req,name=minerAddr" json:"minerAddr,omitempty"`
	Power     *int64  `protobuf:"varint,1,req,name=power" json:"power,omitempty"`
	// contains filtered or unexported fields
}

func (*Miner) Descriptor deprecated

func (*Miner) Descriptor() ([]byte, []int)

Deprecated: Use Miner.ProtoReflect.Descriptor instead.

func (*Miner) GetMinerAddr

func (x *Miner) GetMinerAddr() string

func (*Miner) GetPower

func (x *Miner) GetPower() int64

func (*Miner) ProtoMessage

func (*Miner) ProtoMessage()

func (*Miner) ProtoReflect

func (x *Miner) ProtoReflect() protoreflect.Message

func (*Miner) Reset

func (x *Miner) Reset()

func (*Miner) String

func (x *Miner) String() string

type Msg

type Msg struct {
	Type      *Msg_Type `protobuf:"varint,1,req,name=type,enum=Msg_Type" json:"type,omitempty"`
	Hello     *Hello    `protobuf:"bytes,2,opt,name=hello" json:"hello,omitempty"`
	Miner     *Miner    `protobuf:"bytes,3,opt,name=miner" json:"miner,omitempty"`
	Timestamp *int64    `protobuf:"varint,4,req,name=timestamp" json:"timestamp,omitempty"`
	// contains filtered or unexported fields
}

func NewP2pMinerMsg

func NewP2pMinerMsg(addr string, power int64, timestamp int64) *Msg

func (*Msg) Descriptor deprecated

func (*Msg) Descriptor() ([]byte, []int)

Deprecated: Use Msg.ProtoReflect.Descriptor instead.

func (*Msg) GetHello

func (x *Msg) GetHello() *Hello

func (*Msg) GetMiner

func (x *Msg) GetMiner() *Miner

func (*Msg) GetTimestamp

func (x *Msg) GetTimestamp() int64

func (*Msg) GetType

func (x *Msg) GetType() Msg_Type

func (*Msg) ProtoMessage

func (*Msg) ProtoMessage()

func (*Msg) ProtoReflect

func (x *Msg) ProtoReflect() protoreflect.Message

func (*Msg) Reset

func (x *Msg) Reset()

func (*Msg) String

func (x *Msg) String() string

type Msg_Type

type Msg_Type int32
const (
	Msg_Hello Msg_Type = 0
	Msg_Miner Msg_Type = 1
)

func (Msg_Type) Descriptor

func (Msg_Type) Descriptor() protoreflect.EnumDescriptor

func (Msg_Type) Enum

func (x Msg_Type) Enum() *Msg_Type

func (Msg_Type) EnumDescriptor deprecated

func (Msg_Type) EnumDescriptor() ([]byte, []int)

Deprecated: Use Msg_Type.Descriptor instead.

func (Msg_Type) Number

func (x Msg_Type) Number() protoreflect.EnumNumber

func (Msg_Type) String

func (x Msg_Type) String() string

func (Msg_Type) Type

func (*Msg_Type) UnmarshalJSON deprecated

func (x *Msg_Type) UnmarshalJSON(b []byte) error

Deprecated: Do not use.

type P2pConfig

type P2pConfig struct {
	PrivateKey string
	Port       int
	Bootstrap  []string
}

func NewP2pConfig

func NewP2pConfig(privateKey string, port int, bootstrap []string) *P2pConfig

Jump to

Keyboard shortcuts

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