packet

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package packet provides network messaging protocol and serialization layer.

Packet can be created with shortcut:

senderAddr, _ := host.NewAddress("127.0.0.1:1337")
receiverAddr, _ := host.NewAddress("127.0.0.1:1338")

sender := host.NewHost(senderAddr)
receiver := host.NewHost(receiverAddr)

msg := packet.NewPingPacket(sender, receiver)

// do something with packet

Or with builder:

builder := packet.NewBuilder()

senderAddr, _ := host.NewAddress("127.0.0.1:1337")
receiverAddr, _ := host.NewAddress("127.0.0.1:1338")

sender := host.NewHost(senderAddr)
receiver := host.NewHost(receiverAddr)

msg := builder.
	Sender(sender).
	Receiver(receiver).
	Type(packet.TypeFindHost).
	Request(&packet.RequestDataFindHost{}).
	Build()

// do something with packet

Packet may be serialized:

msg := &packet.Packet{}
serialized, err := packet.SerializePacket(msg)

if err != nil {
	panic(err.Error())
}

fmt.Println(serialized)

And deserialized therefore:

var buffer bytes.Buffer

// Fill buffer somewhere

msg, err := packet.DeserializePacket(buffer)

if err != nil {
	panic(err.Error())
}

// do something with packet

Index

Constants

View Source
const (
	// Unknown - unknown command.
	Unknown = CommandType(iota + 1)
	// StartRelay - command start relay.
	StartRelay
	// StopRelay - command stop relay.
	StopRelay
	// BeginAuthentication - begin authentication.
	BeginAuthentication
	// RevokeAuthentication - revoke authentication.
	RevokeAuthentication
)
View Source
const (
	// Error - some error, see error string.
	Error = CheckNodePrivState(iota + 1)
	// Confirmed - state confirmed.
	Confirmed
	// Declined - state declined.
	Declined
)

Variables

This section is empty.

Functions

func SerializePacket

func SerializePacket(q *Packet) ([]byte, error)

SerializePacket converts packet to byte slice.

Types

type Builder

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

Builder allows lazy building of packets. Each operation returns new copy of a builder.

func NewBuilder

func NewBuilder(sender *host.Host) Builder

NewBuilder returns empty packet builder.

func (Builder) Build

func (cb Builder) Build() (packet *Packet)

Build returns configured packet.

func (Builder) Error

func (cb Builder) Error(err error) Builder

Error adds error description to packet.

func (Builder) Receiver

func (cb Builder) Receiver(host *host.Host) Builder

Receiver sets packet receiver.

func (Builder) Request

func (cb Builder) Request(request interface{}) Builder

Request adds request data to packet.

func (Builder) Response

func (cb Builder) Response(response interface{}) Builder

Response adds response data to packet

func (Builder) Type

func (cb Builder) Type(packetType types.PacketType) Builder

Type sets packet type.

type CheckNodePrivState

type CheckNodePrivState int

CheckNodePrivState - state of check node privileges request.

type CommandType

type CommandType int

CommandType - type for commands.

type Packet

type Packet struct {
	Sender        *host.Host
	Receiver      *host.Host
	Type          types.PacketType
	RequestID     RequestID
	RemoteAddress string

	Data       interface{}
	Error      error
	IsResponse bool
}

Packet is DHT packet object.

func DeserializePacket

func DeserializePacket(conn io.Reader) (*Packet, error)

DeserializePacket reads packet from io.Reader.

func NewPingPacket

func NewPingPacket(sender, receiver *host.Host) *Packet

NewPingPacket can be used as a shortcut for creating ping packets instead of packet Builder.

func (*Packet) IsForMe

func (m *Packet) IsForMe(origin host.Origin) bool

IsForMe checks if packet is addressed to our host.

func (*Packet) IsValid

func (m *Packet) IsValid() (valid bool)

IsValid checks if packet data is a valid structure for current packet type.

type RequestAuthentication

type RequestAuthentication struct {
	Command CommandType
}

RequestAuthentication is data for authentication.

type RequestCascadeSend

type RequestCascadeSend struct {
	RPC  RequestDataRPC
	Data core.Cascade
}

RequestCascadeSend is data for cascade sending feature

type RequestCheckNodePriv

type RequestCheckNodePriv struct {
	RoleKey string
}

RequestCheckNodePriv is data for check node privileges.

type RequestCheckOrigin

type RequestCheckOrigin struct {
}

RequestCheckOrigin is data to check originality.

type RequestCheckSignedNonce

type RequestCheckSignedNonce struct {
	Signed    []byte
	NodeID    core.RecordRef
	NodeRoles []core.NodeRole
	Version   string
}

RequestCheckSignedNonce is data to check a signed nonce.

type RequestDataFindHost

type RequestDataFindHost struct {
	Target []byte
}

RequestDataFindHost is data for FindHost request.

type RequestDataFindValue

type RequestDataFindValue struct {
	Target []byte
}

RequestDataFindValue is data for FindValue request.

type RequestDataRPC

type RequestDataRPC struct {
	NodeID core.RecordRef
	Method string
	Args   [][]byte
}

RequestDataRPC is data for RPC request.

type RequestDataStore

type RequestDataStore struct {
	Data       []byte
	Publishing bool // Whether or not we are the original publisher.
}

RequestDataStore is data for Store request.

type RequestDisconnect

type RequestDisconnect struct {
}

RequestDisconnect is request to disconnect from active list.

type RequestExchangeUnsyncHash

type RequestExchangeUnsyncHash struct {
	SenderID   core.RecordRef
	Pulse      core.PulseNumber
	UnsyncHash []*network.NodeUnsyncHash
}

RequestExchangeUnsyncHash is request to exchange hash of merged unsync lists during consensus

type RequestExchangeUnsyncLists

type RequestExchangeUnsyncLists struct {
	SenderID   core.RecordRef
	Pulse      core.PulseNumber
	UnsyncList []*core.Node
}

RequestExchangeUnsyncLists is request to exchange unsync lists during consensus

type RequestGetNonce

type RequestGetNonce struct {
	NodeID core.RecordRef
}

RequestGetNonce is data to check a public key.

type RequestGetRandomHosts

type RequestGetRandomHosts struct {
	HostsNumber int
}

RequestGetRandomHosts is data for the call that returns random hosts of the DHT network

type RequestID

type RequestID uint64

RequestID is 64 bit unsigned int request id.

type RequestKnownOuterHosts

type RequestKnownOuterHosts struct {
	ID         string // origin ID
	OuterHosts int    // number of known outer hosts
}

RequestKnownOuterHosts is data to notify home subnet about known outer hosts.

type RequestObtainIP

type RequestObtainIP struct {
}

RequestObtainIP is data to obtain a self IP.

type RequestPulse

type RequestPulse struct {
	Pulse core.Pulse
}

RequestPulse is data received from a pulsar

type RequestRelay

type RequestRelay struct {
	Command CommandType
}

RequestRelay is data for relay request (commands: start/stop relay).

type RequestRelayOwnership

type RequestRelayOwnership struct {
	Ready bool
}

RequestRelayOwnership is data to notify that current host can be a relay.

type ResponseAuthentication

type ResponseAuthentication struct {
	Success       bool
	AuthUniqueKey []byte
}

ResponseAuthentication is data for authentication request response.

type ResponseCascadeSend

type ResponseCascadeSend struct {
	Success bool
	Error   string
}

ResponseCascadeSend is the response data of a cascade sending call

type ResponseCheckNodePriv

type ResponseCheckNodePriv struct {
	State CheckNodePrivState
	Error string
}

ResponseCheckNodePriv is data for check node privileges response.

type ResponseCheckOrigin

type ResponseCheckOrigin struct {
	AuthUniqueKey []byte
}

ResponseCheckOrigin is data for check originality request response.

type ResponseCheckSignedNonce

type ResponseCheckSignedNonce struct {
	Error       string
	ActiveNodes []*core.Node
}

type ResponseDataFindHost

type ResponseDataFindHost struct {
	Closest []*host.Host
}

ResponseDataFindHost is data for FindHost response.

type ResponseDataFindValue

type ResponseDataFindValue struct {
	Closest []*host.Host
	Value   []byte
}

ResponseDataFindValue is data for FindValue response.

type ResponseDataRPC

type ResponseDataRPC struct {
	Success bool
	Result  []byte
	Error   string
}

ResponseDataRPC is data for RPC response.

type ResponseDataStore

type ResponseDataStore struct {
	Success bool
}

ResponseDataStore is data for Store response.

type ResponseDisconnect

type ResponseDisconnect struct {
	Disconnected bool
	Error        error
}

ResponseDisconnect id data to answer to disconnected node.

type ResponseExchangeUnsyncHash

type ResponseExchangeUnsyncHash struct {
	UnsyncHash []*network.NodeUnsyncHash
	Error      string
}

RequestExchangeUnsyncHash is request to exchange hash of merged unsync lists during consensus

type ResponseExchangeUnsyncLists

type ResponseExchangeUnsyncLists struct {
	UnsyncList []*core.Node
	Error      string
}

RequestExchangeUnsyncLists is request to exchange unsync lists during consensus

type ResponseGetNonce

type ResponseGetNonce struct {
	Nonce []byte
	Error string
}

ResponseGetNonce is data to answer to authorization request.

type ResponseGetRandomHosts

type ResponseGetRandomHosts struct {
	Hosts []host.Host
	Error string
}

ResponseGetRandomHosts is the response containing random hosts of the DHT network

type ResponseKnownOuterHosts

type ResponseKnownOuterHosts struct {
	ID         string // 	id of host in which more known outer hosts
	OuterHosts int    // number of known outer hosts
}

ResponseKnownOuterHosts is data to answer if origin host know more outer hosts.

type ResponseObtainIP

type ResponseObtainIP struct {
	IP string
}

ResponseObtainIP is data for get a IP of requesting host.

type ResponsePulse

type ResponsePulse struct {
	Success bool
	Error   string
}

ResponsePulse is the response for a new pulse from a pulsar

type ResponseRelay

type ResponseRelay struct {
	State relay.State
}

ResponseRelay is data for relay request response.

type ResponseRelayOwnership

type ResponseRelayOwnership struct {
	Accepted bool
}

ResponseRelayOwnership is data to response to relay ownership request.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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