p2p

package
v1.1.0-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EqualEvent

func EqualEvent(a, b Event) bool

EqualEvent is used to compare the values of the union

Types

type Event

type Event interface {
	encoding.UnionValue
	Type() EventType
}

func CopyEvent

func CopyEvent(v Event) Event

CopyEvent copies a Event.

func NewEvent

func NewEvent(typ EventType) (Event, error)

NewEvent creates a new Event for the specified EventType.

func UnmarshalEvent

func UnmarshalEvent(data []byte) (Event, error)

UnmarshalEvent unmarshals a Event.

func UnmarshalEventFrom

func UnmarshalEventFrom(rd io.Reader) (Event, error)

UnmarshalEventFrom unmarshals a Event.

func UnmarshalEventJSON

func UnmarshalEventJSON(data []byte) (Event, error)

UnmarshalEventJson unmarshals a Event.

type EventType

type EventType uint64
const EventTypeServiceRegistered EventType = 1

EventTypeServiceRegistered .

func EventTypeByName

func EventTypeByName(name string) (EventType, bool)

EventTypeByName returns the named Event Type.

func (EventType) GetEnumValue

func (v EventType) GetEnumValue() uint64

GetEnumValue returns the value of the Event Type

func (EventType) MarshalJSON

func (v EventType) MarshalJSON() ([]byte, error)

MarshalJSON marshals the Event Type to JSON as a string.

func (*EventType) SetEnumValue

func (v *EventType) SetEnumValue(id uint64) bool

SetEnumValue sets the value. SetEnumValue returns false if the value is invalid.

func (EventType) String

func (v EventType) String() string

String returns the name of the Event Type.

func (*EventType) UnmarshalJSON

func (v *EventType) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the Event Type from JSON as a string.

type MessageStreamHandler

type MessageStreamHandler func(message.Stream)

A MessageStreamHandler handles an incoming message.Stream.

type Node

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

Node implements peer-to-peer routing of API v3 messages over via binary message transport.

func New

func New(opts Options) (_ *Node, err error)

New creates a node with the given Options.

func (*Node) Addrs

func (n *Node) Addrs() []multiaddr.Multiaddr

Addrs lists the node's addresses.

func (*Node) Close

func (n *Node) Close() error

Close shuts down the host and topics.

func (*Node) ConnectDirectly

func (n *Node) ConnectDirectly(m *Node) error

ConnectDirectly connects this node directly to another node.

func (*Node) Dialer

func (n *Node) Dialer() message.MultiDialer

Dialer returns a message.MultiDialer that knows how to dial any partition or node in the network.

func (*Node) ID

func (n *Node) ID() peer.ID

func (*Node) RegisterService

func (n *Node) RegisterService(sa *api.ServiceAddress, handler MessageStreamHandler) bool

RegisterService registers a service handler.

func (*Node) SelfDialer

func (n *Node) SelfDialer() message.Dialer

SelfDialer returns a message.Dialer that always returns a stream for the current node.

func (*Node) WaitForService

func (s *Node) WaitForService(ctx context.Context, addr multiaddr.Multiaddr) error

WaitForService blocks until the given service is available. WaitForService will return once the service is registered on the current node or until the node is informed of a peer with the given service. WaitForService will return immediately if the service is already registered or known.

type Options

type Options struct {
	Logger log.Logger

	// Network is the network the node is a part of. An empty Network indicates
	// the node is not part of any network.
	Network string

	// Listen is an array of addresses to listen on.
	Listen []multiaddr.Multiaddr

	// BootstrapPeers is an array of addresses of the bootstrap peers to connect
	// to on bootup.
	BootstrapPeers []multiaddr.Multiaddr

	// Key is the node's private key. If Key is omitted, the node will
	// generate a new key.
	Key ed25519.PrivateKey

	// DiscoveryMode determines how the node responds to peer discovery
	// requests.
	DiscoveryMode dht.ModeOpt

	// External is the node's external address
	External multiaddr.Multiaddr
}

Options are options for creating a Node.

type ServiceRegisteredEvent

type ServiceRegisteredEvent struct {
	PeerID  p2p.PeerID          `json:"peerID,omitempty" form:"peerID" query:"peerID" validate:"required"`
	Network string              `json:"network,omitempty" form:"network" query:"network" validate:"required"`
	Address *api.ServiceAddress `json:"address,omitempty" form:"address" query:"address" validate:"required"`
	// contains filtered or unexported fields
}

func (*ServiceRegisteredEvent) Copy

func (*ServiceRegisteredEvent) CopyAsInterface

func (v *ServiceRegisteredEvent) CopyAsInterface() interface{}

func (*ServiceRegisteredEvent) Equal

func (*ServiceRegisteredEvent) IsValid

func (v *ServiceRegisteredEvent) IsValid() error

func (*ServiceRegisteredEvent) MarshalBinary

func (v *ServiceRegisteredEvent) MarshalBinary() ([]byte, error)

func (*ServiceRegisteredEvent) MarshalJSON

func (v *ServiceRegisteredEvent) MarshalJSON() ([]byte, error)

func (*ServiceRegisteredEvent) Type

func (*ServiceRegisteredEvent) UnmarshalBinary

func (v *ServiceRegisteredEvent) UnmarshalBinary(data []byte) error

func (*ServiceRegisteredEvent) UnmarshalBinaryFrom

func (v *ServiceRegisteredEvent) UnmarshalBinaryFrom(rd io.Reader) error

func (*ServiceRegisteredEvent) UnmarshalFieldsFrom

func (v *ServiceRegisteredEvent) UnmarshalFieldsFrom(reader *encoding.Reader) error

func (*ServiceRegisteredEvent) UnmarshalJSON

func (v *ServiceRegisteredEvent) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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