types

package
v0.0.0-...-06f47f4 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsKnownMsgType

func IsKnownMsgType(t int32) bool

Types

type DHTMessage

type DHTMessage struct {
	Type          MessageType
	ClusterLevel  int32
	Key           string
	Record        *DHTRecord
	CloserPeers   []peer.AddrInfo
	ProviderPeers []peer.AddrInfo
	// contains filtered or unexported fields
}

DHTMessage is what peers use to communicate This is a human-readable wrapper around dht.pb.Message

func NewDHTMsg

func NewDHTMsg(raw []byte) (*DHTMessage, error)

Converts a raw byte message to a DHTMessage

func (*DHTMessage) Marshal

func (msg *DHTMessage) Marshal() ([]byte, error)

type DHTRecord

type DHTRecord struct {
	Key          string
	Value        []byte
	TimeReceived string
}

type IDMap

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

func NewIDMap

func NewIDMap() *IDMap

func (*IDMap) Add

func (m *IDMap) Add(id peer.ID) bool

Add adds the ID to the map, doing nothing if it is already in the map.

Returns true if the ID was added.

func (*IDMap) Contains

func (m *IDMap) Contains(id peer.ID) bool

func (*IDMap) Count

func (m *IDMap) Count() int

func (*IDMap) Remove

func (m *IDMap) Remove(id peer.ID) bool

Remove removes the ID from the map, doing nothing if it is not in the map.

Returns true if the ID was removed.

type MessageType

type MessageType int32
const (
	PUT_VALUE MessageType = iota
	GET_VALUE
	ADD_PROVIDER
	GET_PROVIDERS
	FIND_NODE
	PING
)

type Peer

type Peer struct {
	*events.Emitter
	ID    peer.ID
	Addrs []ma.Multiaddr
	// contains filtered or unexported fields
}

Peer represents a connection with a peer

func NewPeer

func NewPeer(addr peer.AddrInfo) *Peer

func (*Peer) Disconnect

func (p *Peer) Disconnect()

func (*Peer) HangUp

func (p *Peer) HangUp()

func (*Peer) SetStream

func (p *Peer) SetStream(stream network.Stream)

func (*Peer) TryConnect

func (p *Peer) TryConnect(host host.Host, proto protocol.ID)

func (*Peer) Worker

func (p *Peer) Worker(ctx context.Context, pStore peerstore.Peerstore)

type PeerList

type PeerList struct {
	*events.Emitter
	// contains filtered or unexported fields
}

func NewPeerList

func NewPeerList(notifySize int) *PeerList

func (*PeerList) Add

func (pl *PeerList) Add(p *Peer) bool

Add adds the peer to the list, doing nothing if the peer is already in the list.

Returns true if the peer was successfully added

func (*PeerList) AddAll

func (pl *PeerList) AddAll(peers []*Peer)

func (*PeerList) Count

func (pl *PeerList) Count() int

func (*PeerList) ForEach

func (pl *PeerList) ForEach(cb func(p *Peer) bool) uint64

ForEach iterates over all peers, calling the callback for each peer. If the callback returns true, the peer will be removed after iteration. ForEach returns the number of peers removed

NOTE: This method may hold pl.mu.Lock for a long time

func (*PeerList) Pop

func (pl *PeerList) Pop() (*Peer, bool)

Removes a peer from the list and returns it. If the list is empty, returns false Otherwise, returns true

func (*PeerList) Remove

func (pl *PeerList) Remove(p *Peer) bool

Remove removes the peer from the list, doing nothing if the peer was not in the list.

Returns true if the peer was successfully removed

Jump to

Keyboard shortcuts

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