peerdb

package
v0.31.1 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPeerNotFound = leveldb.ErrNotFound
)
View Source
var File_p2p_node_peerManager_peerdb_peer_info_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type AddrInfo

type AddrInfo struct {
	peer.AddrInfo
}

func (*AddrInfo) ProtoDecode

func (addr *AddrInfo) ProtoDecode(protoAddr *ProtoAddrInfo) error

func (*AddrInfo) ProtoEncode

func (addr *AddrInfo) ProtoEncode() *ProtoAddrInfo

type PeerDB

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

PeerDB implements the ipfs Datastore interface and exposes an API for storing and retrieving peers using levelDB as the underlying database

func NewPeerDB

func NewPeerDB(dbDirName string, locationName string) (*PeerDB, error)

Returns a new PeerDB instance

func (*PeerDB) Close

func (p *PeerDB) Close() error

Close closes the datastore. If the datastore is already closed, this returns ErrClosed.

func (*PeerDB) Delete

func (p *PeerDB) Delete(_ context.Context, key datastore.Key) error

Delete removes the value for given `key`. If the key is not in the datastore, this method returns no error.

func (*PeerDB) Get

func (p *PeerDB) Get(_ context.Context, key datastore.Key) (value []byte, err error)

Get retrieves the object `value` named by `key`. Get will return ErrNotFound if the key is not mapped to a value.

func (*PeerDB) GetPeerCount

func (pdb *PeerDB) GetPeerCount() int

Returns the number of peers stored in the database

func (*PeerDB) GetSize

func (p *PeerDB) GetSize(_ context.Context, key datastore.Key) (size int, err error)

GetSize returns the size of the `value` named by `key`. In some contexts, it may be much cheaper to only get the size of the value rather than retrieving the value itself.

func (*PeerDB) Has

func (p *PeerDB) Has(_ context.Context, key datastore.Key) (exists bool, err error)

Has returns whether the `key` is mapped to a `value`. In some contexts, it may be much cheaper only to check for existence of a value, rather than retrieving the value itself. (e.g. HTTP HEAD). The default implementation is found in `GetBackedHas`.

func (*PeerDB) Put

func (p *PeerDB) Put(_ context.Context, key datastore.Key, value []byte) error

Put stores the object `value` named by `key`.

The generalized Datastore interface does not impose a value type, allowing various datastore middleware implementations (which do not handle the values directly) to be composed together.

Ultimately, the lowest-level datastore will need to do some value checking or risk getting incorrect values. It may also be useful to expose a more type-safe interface to your application, and do the checking up-front.

func (*PeerDB) Query

func (p *PeerDB) Query(ctx context.Context, q query.Query) (query.Results, error)

Query searches the datastore and returns a query result. This function may return before the query actually runs. To wait for the query:

result, _ := ds.Query(q)

use the channel interface; result may come in at different times:
for entry := range result.Next() { ... }

or wait for the query to be completely done:
entries, _ := result.Rest()
for entry := range entries { ... }

func (*PeerDB) Sync

func (p *PeerDB) Sync(ctx context.Context, prefix datastore.Key) error

Sync Method Sync guarantees that any Put or Delete calls under prefix that returned before Sync(prefix) was called will be observed after Sync(prefix) returns, even if the program crashes. If Put/Delete operations already satisfy these requirements then Sync may be a no-op.

If the prefix fails to Sync this method returns an error.

type PeerInfo

type PeerInfo struct {
	AddrInfo  AddrInfo
	PubKey    []byte
	Entropy   uint64
	Protected bool
}

contains the information of a peer that is stored in the peerDB as Value

func (*PeerInfo) ProtoDecode

func (pi *PeerInfo) ProtoDecode(ppi *ProtoPeerInfo) error

func (*PeerInfo) ProtoEncode

func (pi *PeerInfo) ProtoEncode() *ProtoPeerInfo

ProtoEncode converts the hash into the ProtoHash type

type ProtoAddrInfo

type ProtoAddrInfo struct {
	ID    string   `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"`
	Addrs []string `protobuf:"bytes,2,rep,name=Addrs,proto3" json:"Addrs,omitempty"`
	// contains filtered or unexported fields
}

func (*ProtoAddrInfo) Descriptor deprecated

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

Deprecated: Use ProtoAddrInfo.ProtoReflect.Descriptor instead.

func (*ProtoAddrInfo) GetAddrs

func (x *ProtoAddrInfo) GetAddrs() []string

func (*ProtoAddrInfo) GetID

func (x *ProtoAddrInfo) GetID() string

func (*ProtoAddrInfo) ProtoMessage

func (*ProtoAddrInfo) ProtoMessage()

func (*ProtoAddrInfo) ProtoReflect

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

func (*ProtoAddrInfo) Reset

func (x *ProtoAddrInfo) Reset()

func (*ProtoAddrInfo) String

func (x *ProtoAddrInfo) String() string

type ProtoPeerInfo

type ProtoPeerInfo struct {
	AddrInfo  *ProtoAddrInfo `protobuf:"bytes,1,opt,name=addrInfo,proto3" json:"addrInfo,omitempty"`
	PubKey    []byte         `protobuf:"bytes,2,opt,name=pubKey,proto3" json:"pubKey,omitempty"`
	Entropy   uint64         `protobuf:"varint,3,opt,name=entropy,proto3" json:"entropy,omitempty"`
	Protected bool           `protobuf:"varint,4,opt,name=protected,proto3" json:"protected,omitempty"`
	// contains filtered or unexported fields
}

func (*ProtoPeerInfo) Descriptor deprecated

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

Deprecated: Use ProtoPeerInfo.ProtoReflect.Descriptor instead.

func (*ProtoPeerInfo) GetAddrInfo

func (x *ProtoPeerInfo) GetAddrInfo() *ProtoAddrInfo

func (*ProtoPeerInfo) GetEntropy

func (x *ProtoPeerInfo) GetEntropy() uint64

func (*ProtoPeerInfo) GetProtected

func (x *ProtoPeerInfo) GetProtected() bool

func (*ProtoPeerInfo) GetPubKey

func (x *ProtoPeerInfo) GetPubKey() []byte

func (*ProtoPeerInfo) ProtoMessage

func (*ProtoPeerInfo) ProtoMessage()

func (*ProtoPeerInfo) ProtoReflect

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

func (*ProtoPeerInfo) Reset

func (x *ProtoPeerInfo) Reset()

func (*ProtoPeerInfo) String

func (x *ProtoPeerInfo) String() string

Jump to

Keyboard shortcuts

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