dht

package
v0.0.0-...-d8a9520 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2018 License: Apache-2.0 Imports: 17 Imported by: 3

Documentation

Overview

Package dht is a generated protocol buffer package.

It is generated from these files:

proto.proto

It has these top-level messages:

PacketContact
PacketHeader
Packet
PartHeader
Found
FoundNodes
Store
Broadcast
Custom
CustomAnswer
RepeatPlease

Index

Constants

View Source
const (
	HASH_SIZE   = 128
	BUCKET_SIZE = HASH_SIZE / 8
)
View Source
const BUFFER_SIZE = 1024 * 4

Variables

View Source
var Command_name = map[int32]string{
	0:  "NOOP",
	1:  "PING",
	2:  "PONG",
	3:  "STORE",
	4:  "STORED",
	5:  "FETCH",
	6:  "FETCH_NODES",
	7:  "FOUND",
	8:  "FOUND_NODES",
	9:  "BROADCAST",
	10: "CUSTOM",
	11: "CUSTOM_ANSWER",
	12: "REPEAT_PLEASE",
}
View Source
var Command_value = map[string]int32{
	"NOOP":          0,
	"PING":          1,
	"PONG":          2,
	"STORE":         3,
	"STORED":        4,
	"FETCH":         5,
	"FETCH_NODES":   6,
	"FOUND":         7,
	"FOUND_NODES":   8,
	"BROADCAST":     9,
	"CUSTOM":        10,
	"CUSTOM_ANSWER": 11,
	"REPEAT_PLEASE": 12,
}

Functions

This section is empty.

Types

type Broadcast

type Broadcast struct {
	Data []byte `protobuf:"bytes,2,opt,name=Data,json=data,proto3" json:"Data,omitempty"`
}

func (*Broadcast) Descriptor

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

func (*Broadcast) GetData

func (m *Broadcast) GetData() []byte

func (*Broadcast) ProtoMessage

func (*Broadcast) ProtoMessage()

func (*Broadcast) Reset

func (m *Broadcast) Reset()

func (*Broadcast) String

func (m *Broadcast) String() string

type Callback

type Callback func(val Packet, err error)

type CallbackChan

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

type Command

type Command int32
const (
	Command_NOOP          Command = 0
	Command_PING          Command = 1
	Command_PONG          Command = 2
	Command_STORE         Command = 3
	Command_STORED        Command = 4
	Command_FETCH         Command = 5
	Command_FETCH_NODES   Command = 6
	Command_FOUND         Command = 7
	Command_FOUND_NODES   Command = 8
	Command_BROADCAST     Command = 9
	Command_CUSTOM        Command = 10
	Command_CUSTOM_ANSWER Command = 11
	Command_REPEAT_PLEASE Command = 12
)

func (Command) EnumDescriptor

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

func (Command) String

func (x Command) String() string

type Custom

type Custom struct {
	Command Command `protobuf:"varint,1,opt,name=Command,json=command,enum=dht.Command" json:"Command,omitempty"`
	Data    []byte  `protobuf:"bytes,2,opt,name=Data,json=data,proto3" json:"Data,omitempty"`
}

func (*Custom) Descriptor

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

func (*Custom) GetCommand

func (m *Custom) GetCommand() Command

func (*Custom) GetData

func (m *Custom) GetData() []byte

func (*Custom) ProtoMessage

func (*Custom) ProtoMessage()

func (*Custom) Reset

func (m *Custom) Reset()

func (*Custom) String

func (m *Custom) String() string

type CustomAnswer

type CustomAnswer struct {
	Data []byte `protobuf:"bytes,2,opt,name=Data,json=data,proto3" json:"Data,omitempty"`
}

func (*CustomAnswer) Descriptor

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

func (*CustomAnswer) GetData

func (m *CustomAnswer) GetData() []byte

func (*CustomAnswer) ProtoMessage

func (*CustomAnswer) ProtoMessage()

func (*CustomAnswer) Reset

func (m *CustomAnswer) Reset()

func (*CustomAnswer) String

func (m *CustomAnswer) String() string

type Dht

type Dht struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func New

func New(options DhtOptions) *Dht

func (*Dht) Broadcast

func (this *Dht) Broadcast(data interface{})

func (*Dht) Cli

func (this *Dht) Cli()

func (*Dht) CustomCmd

func (this *Dht) CustomCmd(data interface{})

func (*Dht) Fetch

func (this *Dht) Fetch(hash Hash) ([]byte, error)

func (*Dht) GetConnectedNumber

func (this *Dht) GetConnectedNumber() int

func (*Dht) Logger

func (this *Dht) Logger() *logging.Logger

func (*Dht) PrintLocalStore

func (this *Dht) PrintLocalStore()

func (*Dht) PrintRoutingTable

func (this *Dht) PrintRoutingTable()

func (*Dht) Running

func (this *Dht) Running() bool

func (*Dht) Start

func (this *Dht) Start() error

func (*Dht) Stop

func (this *Dht) Stop()

func (*Dht) StorageSize

func (this *Dht) StorageSize() int

func (*Dht) Store

func (this *Dht) Store(value []byte) (Hash, int, error)

func (*Dht) StoreAt

func (this *Dht) StoreAt(hash Hash, value []byte) (Hash, int, error)

func (*Dht) StoredKeys

func (this *Dht) StoredKeys() int

func (*Dht) Wait

func (this *Dht) Wait()

type DhtOptions

type DhtOptions struct {
	NoRepublishOnExit bool
	ListenAddr        string
	BootstrapAddr     string
	Verbose           int
	Cluster           int
	Stats             bool
	Interactif        bool
	OnStore           func(Packet) bool
	OnCustomCmd       func(Packet) interface{}
	OnBroadcast       func(Packet) interface{}
	MaxStorageSize    int
	MaxItemSize       int
}

type Found

type Found struct {
	Header *PartHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"`
}

func (*Found) Descriptor

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

func (*Found) GetHeader

func (m *Found) GetHeader() *PartHeader

func (*Found) ProtoMessage

func (*Found) ProtoMessage()

func (*Found) Reset

func (m *Found) Reset()

func (*Found) String

func (m *Found) String() string

type FoundNodes

type FoundNodes struct {
	Nodes []*PacketContact `protobuf:"bytes,1,rep,name=Nodes,json=nodes" json:"Nodes,omitempty"`
}

func (*FoundNodes) Descriptor

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

func (*FoundNodes) GetNodes

func (m *FoundNodes) GetNodes() []*PacketContact

func (*FoundNodes) ProtoMessage

func (*FoundNodes) ProtoMessage()

func (*FoundNodes) Reset

func (m *FoundNodes) Reset()

func (*FoundNodes) String

func (m *FoundNodes) String() string

type Hash

type Hash []byte

func NewHash

func NewHash(val []byte) Hash

func NewRandomHash

func NewRandomHash() Hash

func (Hash) Redacted

func (this Hash) Redacted() interface{}

type Node

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

func NewNode

func NewNode(dht *Dht, addr net.Addr, hash []byte) *Node

func NewNodeContact

func NewNodeContact(dht *Dht, addr net.Addr, contact PacketContact) *Node

func (*Node) Broadcast

func (this *Node) Broadcast(packet Packet) chan interface{}

func (*Node) Custom

func (this *Node) Custom(value interface{}) chan interface{}

func (*Node) Fetch

func (this *Node) Fetch(hash []byte) chan interface{}

func (*Node) FetchNodes

func (this *Node) FetchNodes(hash []byte) chan interface{}

func (*Node) Found

func (this *Node) Found(packet Packet, hash Hash, value []byte)

func (*Node) FoundNodes

func (this *Node) FoundNodes(packet Packet, nodesContact []*PacketContact)

func (*Node) HandleInPacket

func (this *Node) HandleInPacket(packet Packet)

func (*Node) OnBroadcast

func (this *Node) OnBroadcast(packet Packet)

func (*Node) OnCustom

func (this *Node) OnCustom(packet Packet)

func (*Node) OnCustomAnswer

func (this *Node) OnCustomAnswer(packet Packet, done CallbackChan)

func (*Node) OnFetch

func (this *Node) OnFetch(packet Packet)

func (*Node) OnFetchNodes

func (this *Node) OnFetchNodes(packet Packet)

func (*Node) OnFound

func (this *Node) OnFound(packet Packet, done CallbackChan)

func (*Node) OnFoundNodes

func (this *Node) OnFoundNodes(packet Packet, done CallbackChan)

func (*Node) OnPing

func (this *Node) OnPing(packet Packet)

func (*Node) OnPong

func (this *Node) OnPong(packet Packet, cb CallbackChan)

func (*Node) OnRepeatPlease

func (this *Node) OnRepeatPlease(packet Packet)

func (*Node) OnStore

func (this *Node) OnStore(packet Packet)

func (*Node) OnStored

func (this *Node) OnStored(packet Packet, done CallbackChan)

func (*Node) Ping

func (this *Node) Ping() chan interface{}

func (*Node) Pong

func (this *Node) Pong(responseTo []byte) chan interface{}

func (*Node) Redacted

func (this *Node) Redacted() interface{}

func (*Node) RepeatPlease

func (this *Node) RepeatPlease(hash []byte, value []int32) chan interface{}

func (*Node) Store

func (this *Node) Store(hash Hash, value []byte) chan interface{}

func (*Node) Stored

func (this *Node) Stored(packet Packet, hasStored bool)

type Packet

type Packet struct {
	Header *PacketHeader `protobuf:"bytes,1,opt,name=Header,json=header" json:"Header,omitempty"`
	// Types that are valid to be assigned to Data:
	//	*Packet_Hash
	//	*Packet_Ok
	//	*Packet_FoundNodes
	//	*Packet_Found
	//	*Packet_Store
	//	*Packet_Custom
	//	*Packet_CustomAnswer
	//	*Packet_RepeatPlease
	//	*Packet_Broadcast
	Data isPacket_Data `protobuf_oneof:"Data"`
}

func NewPacket

func NewPacket(dht *Dht, command Command, responseTo Hash, data isPacket_Data) Packet

func (*Packet) Descriptor

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

func (*Packet) GetBroadcast

func (m *Packet) GetBroadcast() *Broadcast

func (*Packet) GetCustom

func (m *Packet) GetCustom() *Custom

func (*Packet) GetCustomAnswer

func (m *Packet) GetCustomAnswer() *CustomAnswer

func (*Packet) GetData

func (m *Packet) GetData() isPacket_Data

func (*Packet) GetFound

func (m *Packet) GetFound() *Found

func (*Packet) GetFoundNodes

func (m *Packet) GetFoundNodes() *FoundNodes

func (*Packet) GetHash

func (m *Packet) GetHash() []byte

func (*Packet) GetHeader

func (m *Packet) GetHeader() *PacketHeader

func (*Packet) GetOk

func (m *Packet) GetOk() bool

func (*Packet) GetRepeatPlease

func (m *Packet) GetRepeatPlease() *RepeatPlease

func (*Packet) GetStore

func (m *Packet) GetStore() *Store

func (*Packet) ProtoMessage

func (*Packet) ProtoMessage()

func (*Packet) Reset

func (m *Packet) Reset()

func (*Packet) String

func (m *Packet) String() string

func (*Packet) XXX_OneofFuncs

func (*Packet) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{})

XXX_OneofFuncs is for the internal use of the proto package.

type PacketContact

type PacketContact struct {
	Hash []byte `protobuf:"bytes,1,opt,name=Hash,json=hash,proto3" json:"Hash,omitempty"`
	Addr string `protobuf:"bytes,2,opt,name=addr" json:"addr,omitempty"`
}

func (*PacketContact) Descriptor

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

func (*PacketContact) GetAddr

func (m *PacketContact) GetAddr() string

func (*PacketContact) GetHash

func (m *PacketContact) GetHash() []byte

func (*PacketContact) ProtoMessage

func (*PacketContact) ProtoMessage()

func (*PacketContact) Reset

func (m *PacketContact) Reset()

func (*PacketContact) String

func (m *PacketContact) String() string

type PacketHeader

type PacketHeader struct {
	DateSent    int64          `protobuf:"varint,1,opt,name=DateSent,json=dateSent" json:"DateSent,omitempty"`
	Command     Command        `protobuf:"varint,2,opt,name=Command,json=command,enum=dht.Command" json:"Command,omitempty"`
	Sender      *PacketContact `protobuf:"bytes,3,opt,name=Sender,json=sender" json:"Sender,omitempty"`
	MessageHash []byte         `protobuf:"bytes,4,opt,name=MessageHash,json=messageHash,proto3" json:"MessageHash,omitempty"`
	ResponseTo  []byte         `protobuf:"bytes,5,opt,name=ResponseTo,json=responseTo,proto3" json:"ResponseTo,omitempty"`
	Nonce       int64          `protobuf:"varint,6,opt,name=Nonce,json=nonce" json:"Nonce,omitempty"`
}

func (*PacketHeader) Descriptor

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

func (*PacketHeader) GetCommand

func (m *PacketHeader) GetCommand() Command

func (*PacketHeader) GetDateSent

func (m *PacketHeader) GetDateSent() int64

func (*PacketHeader) GetMessageHash

func (m *PacketHeader) GetMessageHash() []byte

func (*PacketHeader) GetNonce

func (m *PacketHeader) GetNonce() int64

func (*PacketHeader) GetResponseTo

func (m *PacketHeader) GetResponseTo() []byte

func (*PacketHeader) GetSender

func (m *PacketHeader) GetSender() *PacketContact

func (*PacketHeader) ProtoMessage

func (*PacketHeader) ProtoMessage()

func (*PacketHeader) Reset

func (m *PacketHeader) Reset()

func (*PacketHeader) String

func (m *PacketHeader) String() string

type Packet_Broadcast

type Packet_Broadcast struct {
	Broadcast *Broadcast `protobuf:"bytes,13,opt,name=broadcast,oneof"`
}

type Packet_Custom

type Packet_Custom struct {
	Custom *Custom `protobuf:"bytes,10,opt,name=custom,oneof"`
}

type Packet_CustomAnswer

type Packet_CustomAnswer struct {
	CustomAnswer *CustomAnswer `protobuf:"bytes,11,opt,name=customAnswer,oneof"`
}

type Packet_Found

type Packet_Found struct {
	Found *Found `protobuf:"bytes,7,opt,name=found,oneof"`
}

type Packet_FoundNodes

type Packet_FoundNodes struct {
	FoundNodes *FoundNodes `protobuf:"bytes,6,opt,name=foundNodes,oneof"`
}

type Packet_Hash

type Packet_Hash struct {
	Hash []byte `protobuf:"bytes,2,opt,name=hash,proto3,oneof"`
}

type Packet_Ok

type Packet_Ok struct {
	Ok bool `protobuf:"varint,3,opt,name=ok,oneof"`
}

type Packet_RepeatPlease

type Packet_RepeatPlease struct {
	RepeatPlease *RepeatPlease `protobuf:"bytes,12,opt,name=repeatPlease,oneof"`
}

type Packet_Store

type Packet_Store struct {
	Store *Store `protobuf:"bytes,8,opt,name=store,oneof"`
}

type PartHeader

type PartHeader struct {
	Id    int32  `protobuf:"varint,1,opt,name=Id,json=id" json:"Id,omitempty"`
	Total int32  `protobuf:"varint,2,opt,name=Total,json=total" json:"Total,omitempty"`
	Hash  []byte `protobuf:"bytes,3,opt,name=Hash,json=hash,proto3" json:"Hash,omitempty"`
	Data  []byte `protobuf:"bytes,4,opt,name=Data,json=data,proto3" json:"Data,omitempty"`
}

func (*PartHeader) Descriptor

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

func (*PartHeader) GetData

func (m *PartHeader) GetData() []byte

func (*PartHeader) GetHash

func (m *PartHeader) GetHash() []byte

func (*PartHeader) GetId

func (m *PartHeader) GetId() int32

func (*PartHeader) GetTotal

func (m *PartHeader) GetTotal() int32

func (*PartHeader) ProtoMessage

func (*PartHeader) ProtoMessage()

func (*PartHeader) Reset

func (m *PartHeader) Reset()

func (*PartHeader) String

func (m *PartHeader) String() string

type Query

type Query struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewQuery

func NewQuery(hash []byte, job QueryJob, dht *Dht) *Query

func (*Query) Run

func (this *Query) Run() interface{}

func (*Query) WaitResult

func (this *Query) WaitResult() interface{}

type QueryJob

type QueryJob func(*Node) chan interface{}

type RepeatCmd

type RepeatCmd struct {
	Hash  []byte
	Value []int
}

type RepeatPlease

type RepeatPlease struct {
	Hash []byte  `protobuf:"bytes,1,opt,name=Hash,json=hash,proto3" json:"Hash,omitempty"`
	Data []int32 `protobuf:"varint,2,rep,packed,name=Data,json=data" json:"Data,omitempty"`
}

func (*RepeatPlease) Descriptor

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

func (*RepeatPlease) GetData

func (m *RepeatPlease) GetData() []int32

func (*RepeatPlease) GetHash

func (m *RepeatPlease) GetHash() []byte

func (*RepeatPlease) ProtoMessage

func (*RepeatPlease) ProtoMessage()

func (*RepeatPlease) Reset

func (m *RepeatPlease) Reset()

func (*RepeatPlease) String

func (m *RepeatPlease) String() string

type Routing

type Routing struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewRouting

func NewRouting() *Routing

func (*Routing) AddNode

func (this *Routing) AddNode(contact PacketContact)

func (*Routing) FindNode

func (this *Routing) FindNode(hash []byte) []PacketContact

func (*Routing) GetAllNodes

func (this *Routing) GetAllNodes() []PacketContact

func (*Routing) GetByAddr

func (this *Routing) GetByAddr(addr string) (PacketContact, error)

func (*Routing) GetNode

func (this *Routing) GetNode(hash []byte) (PacketContact, error)

func (*Routing) IsBestStorage

func (this *Routing) IsBestStorage(hash []byte) (bool, []PacketContact)

func (*Routing) Print

func (this *Routing) Print()

func (*Routing) RemoveNode

func (this *Routing) RemoveNode(contact PacketContact)

func (*Routing) Size

func (this *Routing) Size() int

type Store

type Store struct {
	Header *PartHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"`
}

func (*Store) Descriptor

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

func (*Store) GetHeader

func (m *Store) GetHeader() *PartHeader

func (*Store) ProtoMessage

func (*Store) ProtoMessage()

func (*Store) Reset

func (m *Store) Reset()

func (*Store) String

func (m *Store) String() string

type StoreInst

type StoreInst struct {
	Hash Hash
	Data []byte
}

type WaitingPartMsg

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

type WorkerJob

type WorkerJob func() chan interface{}

type WorkerQueue

type WorkerQueue struct {
	sync.RWMutex

	Results chan WorkerResult
	// contains filtered or unexported fields
}

func NewWorkerQueue

func NewWorkerQueue(size, buffer int) *WorkerQueue

func (*WorkerQueue) Add

func (this *WorkerQueue) Add(job WorkerJob)

func (*WorkerQueue) IsRunning

func (this *WorkerQueue) IsRunning() bool

func (*WorkerQueue) OnDone

func (this *WorkerQueue) OnDone()

func (*WorkerQueue) Start

func (this *WorkerQueue) Start()

func (*WorkerQueue) Stop

func (this *WorkerQueue) Stop()

func (*WorkerQueue) WaitingCount

func (this *WorkerQueue) WaitingCount() int

type WorkerResult

type WorkerResult interface{}

Jump to

Keyboard shortcuts

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