packet

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: May 2, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const NoID = 2147483648

NoID is the identifier for a packet without a session.

Variables

View Source
var ANSWER = byte(1)

ANSWER is a tag for a response packet

View Source
var AuthentCode = byte(1)

AuthentCode is the code identifying an AuthentPacket

View Source
var BLOCK = byte(0)

BLOCK tags the BlockRequestPacket as a blocking packet for further request

View Source
var BandwidthCode = byte(19)

BandwidthCode identifies a ValidPacket requesting a request or an update of the bandwidth limitation

View Source
var BlockRequestCode = byte(24)

BlockRequestCode is the code identifying an BlockRequestPacket

View Source
var CancelCode = byte(10)

CancelCode identifies a ValidPacket requesting the cancelation of a transfer

View Source
var ConfExportCode = byte(11)

ConfExportCode identifies a ValidPacket requesting an export of configuration

View Source
var ConfImportCode = byte(12)

ConfImportCode identifies a ValidPacket requesting an import of configuration

View Source
var ConnectionErrorCode = byte(6)

ConnectionErrorCode is the code identifying an ConnectionErrorPacket

View Source
var DataCode = byte(3)

DataCode is the code identifying an DataPacket

View Source
var EndRequestCode = byte(20)

EndRequestCode is the code identifying an EndRequestPacket

View Source
var EndTransferCode = byte(14)

EndTransferCode is the code identifying an EndTransferPacket

View Source
var ErrorCode = byte(5)

ErrorCode is the code identifying an ErrorPacket

View Source
var InformationCode = byte(18)

InformationCode is the code identifying an InformationPacket

View Source
var JSONRequestCode = byte(25)

JSONRequestCode is the code identifying an JSONRequestPacket

View Source
var KeepAliveCode = byte(21)

KeepAliveCode is the code identifying an KeepAlivePacket

View Source
var LogCode = byte(16)

LogCode identifies a ValidPacket requesting an export of the logs

View Source
var LogPurgeCode = byte(17)

LogPurgeCode identifies a ValidPacket requesting a purge of the logs

View Source
var NoopCode = byte(23)

NoopCode is the code identifying an NoopPacket

View Source
var QUESTION = byte(0)

QUESTION is a marker for a packet which require an answer

View Source
var RequestCode = byte(7)

RequestCode is the code identifying an RequestPacket

View Source
var RequestUserCode = byte(15)

RequestUserCode identifies a ValidPakcet as a response to a request

View Source
var ShutdownCode = byte(8)

ShutdownCode is the code identifying an ShutdownPacket

View Source
var StopCode = byte(9)

StopCode identifies a ValidPacket requesting the halt of a transfer

View Source
var TestCode = byte(13)

TestCode is the code identifying an TestPacket

View Source
var UNBLOCK = byte(1)

UNBLOCK tags the BlockRequestPacket as an unblocking packet for further request

View Source
var ValidCode = byte(4)

ValidCode is the code identifying an ValidPacket

Functions

This section is empty.

Types

type AuthentJSON

type AuthentJSON struct {
	// The hostid of the partner (redundant with packet.Login)
	HostID string `json:"HostID"`
	// The version of the protocol used (formated as major.minor.path)
	Version string `json:"Version"`
	// Will the partner provide the size of the file when it sends a file
	FileSize bool `json:"FileSize"`
	// Will the partner provide a hash of the file sent at the end of the transfer
	FinalHash bool `json:"FinalHash"`
	// Which hash algorithm the partner will use to hash the file (authorized values are: MD5, SHA-1, SHA-256, SHA-384, SHA-512, ALDER32)
	DigestAlgo string `json:"DigestAlgo"`
	// Is the partner accessed through a proxy
	Proxified bool `json:"Proxified"`
	// Which separator the partner use for separating value (not used)
	Separator string `json:"separator"`
}

AuthentJSON represents the partner configuration expected in the VersionField of an AuthentPacket

type AuthentPacket

type AuthentPacket struct {
	// The login used by the partner
	Login string
	// The password used by the partner
	Password []byte
	// The identifier of the partner session
	LocalID uint32
	// Is the packet a QUESTION (0) client -> server or an ANSWER (1) server -> client
	Way byte
	// The configuration of the partner (see AuthentJSON for more details)
	Version string
}

AuthentPacket is the structure handling the R66 authent packet which provides both login and password to authenticate to the partner as well its configuration

func (*AuthentPacket) GetJSONVersion

func (p *AuthentPacket) GetJSONVersion() (*AuthentJSON, error)

GetJSONVersion unmarshall the VersionField of the provided AuthentPacket and return it as a AuthentJSON pointer TODO Add Tests

func (*AuthentPacket) MarshalBinary

func (p *AuthentPacket) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary form of the packet to send on the network.

func (*AuthentPacket) Read

func (p *AuthentPacket) Read(reader io.Reader, hSize uint32, bSize uint32, fSize uint32) error

Deprecated

func (*AuthentPacket) Type

func (*AuthentPacket) Type() byte

Type returns the code of the packet

func (*AuthentPacket) UnmarshalBinary

func (p *AuthentPacket) UnmarshalBinary(src []byte) error

UnmarshalBinary reads the provided byte array as an AuthentPacket. It returns an error if the byte array doesn't contain an AuthentPacket or if there is not enough data in the array.

type BlockRequestPacket

type BlockRequestPacket struct {
	// The admin password to be authorised to perform the operation.
	Password []byte
	// The tag to block (0) or unblock (1) future transfer requests.
	Block byte
}

BlockRequestPacket is the structure handling the R66 block request packet which requests the partner to refuse (or reaccept) future transfer requests.

func (*BlockRequestPacket) MarshalBinary

func (p *BlockRequestPacket) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary form of the packet to send on the network.

func (*BlockRequestPacket) Read

func (p *BlockRequestPacket) Read(reader io.Reader, hSize uint32, bSize uint32, fSize uint32) error

Deprecated

func (*BlockRequestPacket) Type

func (*BlockRequestPacket) Type() byte

Type returns the code of the packet

func (*BlockRequestPacket) UnmarshalBinary

func (p *BlockRequestPacket) UnmarshalBinary(src []byte) error

UnmarshalBinary reads the provided byte array as a BlockRequest. It returns an error if the byte array doesn't contain a BlockRequest or if there is not enough data in the array.

type ConnectionErrorPacket

type ConnectionErrorPacket struct {
	// TODO
	Message string
	// TODO
	Details string
}

ConnectionErrorPacket is the structure handling the R66 connection error packet which indicate an error while establish the r66 connection.

func (*ConnectionErrorPacket) MarshalBinary

func (p *ConnectionErrorPacket) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary form of the packet to send on the network.

func (*ConnectionErrorPacket) Read

func (p *ConnectionErrorPacket) Read(reader io.Reader, hSize uint32, bSize uint32, fSize uint32) error

Deprecated

func (*ConnectionErrorPacket) Type

func (*ConnectionErrorPacket) Type() byte

Type returns the code of the packet

func (*ConnectionErrorPacket) UnmarshalBinary

func (p *ConnectionErrorPacket) UnmarshalBinary(src []byte) error

UnmarshalBinary reads the provided byte array as a ConnectionErrorPacket. It returns an error if the byte array doesn't contain a ConnectionErrorPacket or if there is not enough data in the array.

type DataPacket

type DataPacket struct {
	// Rank is the numer of the block transmited.
	Rank uint32
	// Hash contains the data block transmited.
	Data []byte
	// Hash contains the hash of the block if the transfer is a hashed transfer.
	Hash []byte

	// Deprecated
	Unlock func()
	// contains filtered or unexported fields
}

DataPacket is the structure handling the R66 data packet which carries the content of the file transfered and eventualy the hash of the content of the packet.

func (*DataPacket) MarshalBinary

func (p *DataPacket) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary form of the packet to send on the network.

func (*DataPacket) Read

func (p *DataPacket) Read(reader io.Reader, hSize uint32, bSize uint32, fSize uint32) error

Read should not be used for a data packet Deprecated

func (*DataPacket) Type

func (*DataPacket) Type() byte

Type returns the code of the packet

func (*DataPacket) UnmarshalBinary

func (p *DataPacket) UnmarshalBinary(src []byte) error

UnmarshalBinary reads the provided byte array as a DataPacket. It returns an error if the byte array doesn't contain a DataPacket or if there is not enough data in the array.

As the DataPacket can be quite large it is advised to directly read the DataPacket in the file rather than use this function.

func (*DataPacket) WritePacket

func (p *DataPacket) WritePacket(writer io.Writer, blockSize uint32) ([]byte, error)

WritePacket writes the content of the packet in the provided writer according to the provided blocksize. It returns the hash of the content or an error if a problem occurs. Deprecated

type EndRequestPacket

type EndRequestPacket struct {
	Code     uint32
	Way      byte
	Optional string
}

EndRequestPacket is the structure handling the R66 end request packet which indicate the end of all the transfer's operations.

func (*EndRequestPacket) MarshalBinary

func (p *EndRequestPacket) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary form of the packet to send on the network.

func (*EndRequestPacket) Read

func (p *EndRequestPacket) Read(reader io.Reader, hSize uint32, bSize uint32, fSize uint32) error

Deprecated

func (*EndRequestPacket) Type

func (*EndRequestPacket) Type() byte

Type returns the code of the packet

func (*EndRequestPacket) UnmarshalBinary

func (p *EndRequestPacket) UnmarshalBinary(src []byte) error

UnmarshalBinary reads the provided byte array as an EndRequestPacket. It returns an error if the byte array doesn't contain an EndRequestPacket or if there is not enough data in the array.

type EndTransferPacket

type EndTransferPacket struct {
	Source byte
	Way    byte
	Hash   []byte
}

EndTransferPacket is the structure handling the R66 end transfer packet which indicate the end the data transfer.

func (*EndTransferPacket) MarshalBinary

func (p *EndTransferPacket) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary form of the packet to send on the network.

func (*EndTransferPacket) Read

func (p *EndTransferPacket) Read(reader io.Reader, hSize uint32, bSize uint32, fSize uint32) error

Deprecated

func (*EndTransferPacket) Type

func (*EndTransferPacket) Type() byte

Type returns the code of the packet

func (*EndTransferPacket) UnmarshalBinary

func (p *EndTransferPacket) UnmarshalBinary(src []byte) error

UnmarshalBinary reads the provided byte array as an EndTransferPacket. It returns an error if the byte array doesn't contain an EndTransferPacket or if there is not enough data in the array.

type ErrorPacket

type ErrorPacket struct {
	Message string
	Code    byte
	Action  uint32
}

ErrorPacket is the structure handling the R66 error packet which provides information on an error which occured during a transfer.

func (*ErrorPacket) MarshalBinary

func (p *ErrorPacket) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary form of the packet to send on the network.

func (*ErrorPacket) Read

func (p *ErrorPacket) Read(reader io.Reader, hSize uint32, bSize uint32, fSize uint32) error

Deprecated

func (*ErrorPacket) Type

func (*ErrorPacket) Type() byte

Type returns the code of the packet

func (*ErrorPacket) UnmarshalBinary

func (p *ErrorPacket) UnmarshalBinary(src []byte) error

UnmarshalBinary reads the provided byte array as an ErrorPacket. It returns an error if the byte array doesn't contain an ErrorPacket or if there is not enough data in the array.

type InformationPacket

type InformationPacket struct {
	Rule          string
	RequestedInfo byte
	File          string
}

InformationPacket is the structure handling the R66 information packet which request informations of the files available through a given rules, or of an existing transfer.

func (*InformationPacket) MarshalBinary

func (p *InformationPacket) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary form of the packet to send on the network.

func (*InformationPacket) Read

func (p *InformationPacket) Read(reader io.Reader, hSize uint32, bSize uint32, fSize uint32) error

Deprecated

func (*InformationPacket) Type

func (*InformationPacket) Type() byte

Type returns the code of the packet

func (*InformationPacket) UnmarshalBinary

func (p *InformationPacket) UnmarshalBinary(src []byte) error

UnmarshalBinary reads the provided byte array as an InformationPacket. It returns an error if the byte array doesn't contain an InformationPacket or if there is not enough data in the array.

type JSONRequest

type JSONRequest struct {
	Class         string `json:"@class"`
	Comment       string `json:"comment"`
	RequestPacket byte   `json:"requestUserPacket"`
	Filename      string `json:"filename"`
	FileSize      int    `json:"filesize"`
	FileInfo      string `json:"fileInfo"`
}

JSONRequest is the structure wrapping the informations of a request passed through a JSONRequestPacket

type JSONRequestPacket

type JSONRequestPacket struct {
	Request *JSONRequest
	Result  string
	Code    byte
}

JSONRequestPacket is the structure handling the R66 JSON request packet which allows specific requests to be used such as the modification of the file information before the transfer.

func (*JSONRequestPacket) MarshalBinary

func (p *JSONRequestPacket) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary form of the packet to send on the network.

func (*JSONRequestPacket) Read

func (p *JSONRequestPacket) Read(reader io.Reader, hSize uint32, bSize uint32, fSize uint32) error

Deprecated

func (*JSONRequestPacket) Type

func (*JSONRequestPacket) Type() byte

Type returns the code of the packet

func (*JSONRequestPacket) UnmarshalBinary

func (p *JSONRequestPacket) UnmarshalBinary(src []byte) error

UnmarshalBinary reads the provided byte array as an JSONRequestPacket. It returns an error if the byte array doesn't contain an JSONRequestPacket, if there is not enough data in the array or if the JSON contained in the packet is malformated.

type KeepAlivePacket

type KeepAlivePacket struct {
	Way byte
}

KeepAlivePacket is the structure handling the R66 keep alive packet which prevent the connection to be dropped by the remote partner.

func (*KeepAlivePacket) MarshalBinary

func (p *KeepAlivePacket) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary form of the packet to send on the network.

func (*KeepAlivePacket) Read

func (p *KeepAlivePacket) Read(reader io.Reader, hSize uint32, bSize uint32, fSize uint32) error

func (*KeepAlivePacket) Type

func (*KeepAlivePacket) Type() byte

Type returns the code of the packet

func (*KeepAlivePacket) UnmarshalBinary

func (p *KeepAlivePacket) UnmarshalBinary(src []byte) error

UnmarshalBinary reads the provided byte array as a KeepAlive. It returns an error if the byte array doesn't contain a KeepAlive or if there is not enough data in the array.

type NetworkPacket

type NetworkPacket struct {
	Size uint32
	// RemoteID is the identifier of the remote session.
	RemoteID uint32
	// LocalID is the identifier of the local session.
	LocalID uint32
	// Type is the identifier of the packet content.
	// FIXME 1.0.0 rename into Code
	Type byte
	// Content is the payload of the NetworkPacket.
	Content R66Packet
}

NetworkPacket is the structure handling the multiplexing part of the R66 packet.

func (*NetworkPacket) MarshalBinary

func (p *NetworkPacket) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary form of the packet to send on the network.

func (*NetworkPacket) ReadPacket

func (p *NetworkPacket) ReadPacket(reader io.Reader) (err error)

ReadPacket fills the NetworkPacket from the provided reader. Deprecated

func (*NetworkPacket) UnmarshalBinary

func (p *NetworkPacket) UnmarshalBinary(src []byte) error

UnmarshalBinary reads the provided byte array as a NetworkPacket. It returns an error if there is not enough data in the array.

This function only unmarshal the network specific part of the packet and not the payload.

type NoopPacket

type NoopPacket struct {
}

NoopPacket is the structure reponsible for handling a R66 noop Packet which do nothing.

func (*NoopPacket) MarshalBinary

func (p *NoopPacket) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary form of the packet to send on the network.

func (*NoopPacket) Read

func (p *NoopPacket) Read(reader io.Reader, hSize uint32, bSize uint32, fSize uint32) error

func (*NoopPacket) Type

func (*NoopPacket) Type() byte

Type returns the code of the packet

func (*NoopPacket) UnmarshalBinary

func (p *NoopPacket) UnmarshalBinary(src []byte) error

UnmarshalBinary reads the provided byte array as a NoopPacket. It returns an error if the byte array doesn't contain a NoopPacket or if there is not enough data in the array.

type R66Packet

type R66Packet interface {
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler

	// FIXME 1.0.0 Rename into Code
	// Type returns the code of the packet
	Type() byte

	// Read reads the packet according to the provided header, body and footer size
	// Deprecated will use encoding.BinaryUnmarshaler instead
	Read(io.Reader, uint32, uint32, uint32) error
}

R66Packet is an interface which all R66 packet must implements

func GetPacket

func GetPacket(r io.Reader) (R66Packet, error)

GetPacket reads a packet from the provided reader. Deprecated

type ReqBody

type ReqBody struct {
	Filename  string `json:"filename"`
	BlockSize uint32 `json:"block"`
	Rank      uint32 `json:"rank"`
	ID        int64  `json:"id"`
	Code      rune   `json:"code"`
	Filesize  int64  `json:"length"`
	Limit     uint32 `json:"limit"`
}

ReqBody is the structure holding the Body of a R66 Request Packet

type ReqHeader

type ReqHeader struct {
	Rule string `json:"rule"`
	Mode uint32 `json:"mode"`
}

ReqHeader is the structure holding the Header of a R66 Request Packet

type RequestPacket

type RequestPacket struct {
	Header       ReqHeader
	Way          byte
	Body         ReqBody
	TransferInfo []byte
}

RequestPacket is the structure reponsible for handling a R66 Request Packet which request a new transfer to be started or an existing.

func (*RequestPacket) MarshalBinary

func (p *RequestPacket) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary form of the packet to send on the network.

func (*RequestPacket) Read

func (p *RequestPacket) Read(reader io.Reader, hSize uint32, bSize uint32, fSize uint32) error

func (*RequestPacket) Type

func (*RequestPacket) Type() byte

Type returns the code of the packet

func (*RequestPacket) UnmarshalBinary

func (p *RequestPacket) UnmarshalBinary(src []byte) error

UnmarshalBinary reads the provided byte array as a Request. It returns an error if the byte array doesn't contain a Request or if there is not enough data in the array.

type ShutdownPacket

type ShutdownPacket struct {
	Password []byte
	Restart  byte
}

ShutdownPacket is the structure reponsible for handling a R66 Shutdown Packet

func (*ShutdownPacket) MarshalBinary

func (p *ShutdownPacket) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary form of the packet to send on the network.

func (*ShutdownPacket) Read

func (p *ShutdownPacket) Read(reader io.Reader, hSize uint32, bSize uint32, fSize uint32) error

func (*ShutdownPacket) Type

func (*ShutdownPacket) Type() byte

Type returns the code of the packet

func (*ShutdownPacket) UnmarshalBinary

func (p *ShutdownPacket) UnmarshalBinary(src []byte) error

UnmarshalBinary reads the provided byte array as a ShutdownPacket. It returns an error if the byte array doesn't contain a ShutdownPacket or if there is not enough data in the array.

type TestPacket

type TestPacket struct {
	Head    string
	Message string
	Ping    uint32
}

TestPacket is the structure reponsible for handling a R66 Test Packet

func (*TestPacket) MarshalBinary

func (p *TestPacket) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary form of the packet to send on the network.

func (*TestPacket) Read

func (p *TestPacket) Read(reader io.Reader, hSize uint32, bSize uint32, fSize uint32) error

func (*TestPacket) Type

func (*TestPacket) Type() byte

Type returns the code of the packet

func (*TestPacket) UnmarshalBinary

func (p *TestPacket) UnmarshalBinary(src []byte) error

UnmarshalBinary reads the provided byte array as a TestPacket. It returns an error if the byte array doesn't contain a TestPacket or if there is not enough data in the array.

type ValidPacket

type ValidPacket struct {
	Head    string
	Message string
	Code    byte
}

ValidPacket is the structure reponsible for handling a R66 Valid Packet

func (*ValidPacket) MarshalBinary

func (p *ValidPacket) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary form of the packet to send on the network.

func (*ValidPacket) Read

func (p *ValidPacket) Read(reader io.Reader, hSize uint32, bSize uint32, fSize uint32) error

func (*ValidPacket) Type

func (*ValidPacket) Type() byte

Type returns the code of the packet

func (*ValidPacket) UnmarshalBinary

func (p *ValidPacket) UnmarshalBinary(src []byte) error

UnmarshalBinary reads the provided byte array as a ValidPacket. It returns an error if the byte array doesn't contain a ValidPacket or if there is not enough data in the array.

Jump to

Keyboard shortcuts

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