network

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxMessagePayloadSize = 32
)
View Source
const (
	MaxPacketPayloadSize = 200
)
View Source
const (
	MaxRPCPayloadSize = 50
)

Variables

View Source
var (
	ErrProtocolVersionNotSupported   = errors.New("protocol version not supported")
	ErrProtocolPortNotSupported      = errors.New("protocol port not supported")
	ErrTransportProtocolNotSupported = errors.New("transport protocol not supported")
)

Functions

This section is empty.

Types

type HandShakeContent

type HandShakeContent struct {
	DIDDocument *did.Document `json:"did_document"`
	Signature   []byte        `json:"signature"` // Signature of the DID Document
	Challenge   []byte        `json:"challenge"` // Random challenge for replay protection
	Version     string        `json:"version"`
}

func NewHandShakeContent

func NewHandShakeContent(didDoc *did.Document, signature, challenge []byte, version string) *HandShakeContent

type Message

type Message interface {
	Encode(w io.Writer) (int, error)
	Decode(r io.Reader) (int, error)
	Bytes() []byte
	Verify(sharedKey []byte) bool
	Len() int
	Max() int
}

func NewMessageContent

func NewMessageContent(msgType common.Message, payload []byte, sharedKey []byte) (Message, error)

type MessageContent

type MessageContent struct {
	Type       common.Message              // Type of message
	PayloadLen uint8                       // Real payload length
	Payload    [MaxMessagePayloadSize]byte // Actual message content or data
	Hash       [32]byte                    // Payload hash
	CreatedAt  int64                       // Timestamp of message creation
}

func (*MessageContent) Bytes

func (m *MessageContent) Bytes() []byte

func (*MessageContent) Decode

func (m *MessageContent) Decode(r io.Reader) (int, error)

func (*MessageContent) Encode

func (m *MessageContent) Encode(w io.Writer) (int, error)

func (*MessageContent) Len

func (m *MessageContent) Len() int

func (*MessageContent) Max

func (m *MessageContent) Max() int

func (*MessageContent) Verify

func (m *MessageContent) Verify(sharedKey []byte) bool

type Packet

type Packet interface {
	GetCommand() common.Command
	Encode(w io.Writer) (int, error)
	Decode(r io.Reader) (int, error)
	Bytes() []byte
	Check() error
	Len() int
	Max() int
}

func NewPacket

func NewPacket(command common.Command, rpc RPC) (Packet, error)

type PacketContent

type PacketContent struct {
	Command    common.Command
	PayloadLen uint16
	Payload    [MaxPacketPayloadSize]byte
	CheckSum   uint64
}

func (*PacketContent) Bytes

func (p *PacketContent) Bytes() []byte

func (*PacketContent) Check

func (p *PacketContent) Check() error

func (*PacketContent) Decode

func (p *PacketContent) Decode(r io.Reader) (int, error)

func (*PacketContent) Encode

func (p *PacketContent) Encode(w io.Writer) (int, error)

func (*PacketContent) GetCommand

func (p *PacketContent) GetCommand() common.Command

func (*PacketContent) Len

func (p *PacketContent) Len() int

func (*PacketContent) Max

func (p *PacketContent) Max() int

type Protocol

type Protocol interface {
	ProtocolInfo() *ProtocolInfo
	IsVersionSupported(string) (bool, error)
	IsPortSupported(int) (bool, error)
	IsProtocolSupported(string) (bool, error)
	GetDefaultVersion() string
	GetDefaultPort() int
	GetDefaultProtocol() string
}

func NewProtocolInfo

func NewProtocolInfo(transport TransportProtocol) Protocol

NewProtocolInfo creates a new ProtocolInfo instance

type ProtocolInfo

type ProtocolInfo struct {
	TransportProtocol TransportProtocol
	Version           ProtocolVersion
	Port              ProtocolPort
}

ProtcolInfo defines the protocol used in the p2p network

func (*ProtocolInfo) GetDefaultPort

func (pi *ProtocolInfo) GetDefaultPort() int

GetDefaultPort returns the default protocol port

func (*ProtocolInfo) GetDefaultProtocol

func (pi *ProtocolInfo) GetDefaultProtocol() string

GetDefaultProtocol returns the default transport protocol

func (*ProtocolInfo) GetDefaultVersion

func (pi *ProtocolInfo) GetDefaultVersion() string

GetDefaultVersion returns the default protocol version

func (*ProtocolInfo) IsPortSupported

func (pi *ProtocolInfo) IsPortSupported(port int) (bool, error)

IsPortSupported checks if the given port is supported

func (*ProtocolInfo) IsProtocolSupported

func (pi *ProtocolInfo) IsProtocolSupported(proto string) (bool, error)

IsProtocolSupported checks if the given protocol is supported

func (*ProtocolInfo) IsVersionSupported

func (pi *ProtocolInfo) IsVersionSupported(version string) (bool, error)

IsVersionSupported checks if the given version is supported

func (*ProtocolInfo) ProtocolInfo

func (pi *ProtocolInfo) ProtocolInfo() *ProtocolInfo

GetProtocolInfo returns the protocol information

type ProtocolPort

type ProtocolPort int

type ProtocolVersion

type ProtocolVersion string

type RPC

type RPC interface {
	Encode(w io.Writer) (int, error)
	Decode(r io.Reader) (int, error)
	Verify(pubKey ed25519.PublicKey) error
	Bytes() []byte
	Len() int
	Max() int
}

func NewRPCContent

func NewRPCContent(msg Message, d did.IdentifierDID) (RPC, error)

type RPCContent

type RPCContent struct {
	From       [50]byte
	PayloadLen uint8
	Payload    [MaxRPCPayloadSize]byte
	Sig        [64]byte
}

func (*RPCContent) Bytes

func (rpc *RPCContent) Bytes() []byte

func (*RPCContent) Decode

func (rpc *RPCContent) Decode(r io.Reader) (int, error)

func (*RPCContent) Encode

func (rpc *RPCContent) Encode(w io.Writer) (int, error)

func (*RPCContent) Len

func (rpc *RPCContent) Len() int

func (*RPCContent) Max

func (rpc *RPCContent) Max() int

func (*RPCContent) Verify

func (rpc *RPCContent) Verify(pub ed25519.PublicKey) error

type TransportProtocol

type TransportProtocol string
const (
	TCPProtocol TransportProtocol = "tcp"
	UDPProtocol TransportProtocol = "udp"
)

Jump to

Keyboard shortcuts

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