xchg

package
v0.0.47 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2022 License: MIT Imports: 28 Imported by: 2

Documentation

Index

Constants

View Source
const (
	UDP_PORT          = 8484
	INPUT_BUFFER_SIZE = 1024 * 1024
)
View Source
const (
	PEER_UDP_START_PORT = 42000
	PEER_UDP_END_PORT   = 42100
)
View Source
const (
	TransactionHeaderSize = 40

	FrameTypeCall     = byte(0x10)
	FrameTypeResponse = byte(0x11)
)
View Source
const (
	ERR_XCHG_ACCESS_DENIED = "{ERR_XCHG_ACCESS_DENIED}"

	// Base Connection
	ERR_XCHG_CONN_WRONG_FRAME_SIZE = "{ERR_XCHG_CONN_WRONG_FRAME_SIZE}"
	ERR_XCHG_CONN_NO_CONNECTION    = "{ERR_XCHG_CONN_NO_CONNECTION}"
	ERR_XCHG_CONN_SENDING_ERROR    = "{ERR_XCHG_CONN_SENDING_ERROR}"

	// Transaction
	ERR_XCHG_TR_WRONG_FRAME = "{ERR_XCHG_TR_WRONG_FRAME}"

	// Client Connection
	// Regular Call
	ERR_XCHG_CL_CONN_CALL_WRONG_FUNCTION_LEN   = "{ERR_XCHG_CL_CONN_CALL_WRONG_FUNCTION_LEN}"
	ERR_XCHG_CL_CONN_CALL_SEARCHING_NODE       = "{ERR_XCHG_CL_CONN_CALL_SEARCHING_NODE}"
	ERR_XCHG_CL_CONN_CALL_NO_LOCAL_PRIVATE_KEY = "{ERR_XCHG_CL_CONN_CALL_NO_LOCAL_PRIVATE_KEY}"
	ERR_XCHG_CL_CONN_CALL_NO_ROUTE_TO_PEER     = "{ERR_XCHG_CL_CONN_CALL_NO_ROUTE_TO_PEER}"
	ERR_XCHG_CL_CONN_CALL_RESP_LEN             = "{ERR_XCHG_CL_CONN_CALL_RESP_LEN}"
	ERR_XCHG_CL_CONN_CALL_RESP_STATUS_BYTE     = "{ERR_XCHG_CL_CONN_CALL_RESP_STATUS_BYTE}"
	ERR_XCHG_CL_CONN_CALL_ENC                  = "{ERR_XCHG_CL_CONN_CALL_ENC}"
	ERR_XCHG_CL_CONN_CALL_ERR                  = "{ERR_XCHG_CL_CONN_CALL_ERR}"
	ERR_XCHG_CL_CONN_CALL_DECRYPT              = "{ERR_XCHG_CL_CONN_CALL_DECRYPT}"
	ERR_XCHG_CL_CONN_CALL_UNPACK               = "{ERR_XCHG_CL_CONN_CALL_UNPACK}"
	ERR_XCHG_CL_CONN_CALL_FROM_PEER            = "{ERR_XCHG_CL_CONN_FROM_PEER}"

	// Auth
	ERR_XCHG_CL_CONN_AUTH_GET_NONCE            = "{ERR_XCHG_CL_CONN_AUTH_GET_NONCE}"
	ERR_XCHG_CL_CONN_AUTH_WRONG_NONCE_LEN      = "{ERR_XCHG_CL_CONN_AUTH_WRONG_NONCE_LEN}"
	ERR_XCHG_CL_CONN_AUTH_NO_LOCAL_PRIVATE_KEY = "{ERR_XCHG_CL_CONN_AUTH_NO_LOCAL_PRIVATE_KEY}"
	ERR_XCHG_CL_CONN_AUTH_NO_REMOTE_PUBLIC_KEY = "{ERR_XCHG_CL_CONN_AUTH_NO_REMOTE_PUBLIC_KEY}"
	ERR_XCHG_CL_CONN_AUTH_ENC                  = "{ERR_XCHG_CL_CONN_AUTH_ENC}"
	ERR_XCHG_CL_CONN_AUTH_AUTH                 = "{ERR_XCHG_CL_CONN_AUTH_AUTH}"
	ERR_XCHG_CL_CONN_AUTH_DECR                 = "{ERR_XCHG_CL_CONN_AUTH_DECR}"
	ERR_XCHG_CL_CONN_AUTH_WRONG_AUTH_RESP_LEN  = "{ERR_XCHG_CL_CONN_AUTH_WRONG_AUTH_RESP_LEN}"

	// Peer Connection
	ERR_XCHG_PEER_CONN_LOSS               = "{ERR_XCHG_PEER_CONN_LOSS}"
	ERR_XCHG_PEER_CONN_TR_TIMEOUT         = "{ERR_XCHG_PEER_CONN_TR_TIMEOUT}"
	ERR_XCHG_PEER_CONN_REQ_SID_SIZE       = "{ERR_XCHG_PEER_CONN_REQ_SID_SIZE}"
	ERR_XCHG_PEER_CONN_WRONG_PROT_VERSION = "{ERR_XCHG_PEER_CONN_WRONG_PROT_VERSION}"
	ERR_XCHG_PEER_CONN_RCVD_ERR           = "{ERR_XCHG_PEER_CONN_RCVD_ERR}"

	// Server Connection
	ERR_XCHG_SRV_CONN_WRONG_SESSION       = "{ERR_XCHG_SRV_CONN_WRONG_SESSION}"
	ERR_XCHG_SRV_CONN_DECR                = "{ERR_XCHG_SRV_CONN_DECR}"
	ERR_XCHG_SRV_CONN_UNPACK              = "{ERR_XCHG_SRV_CONN_UNPACK}"
	ERR_XCHG_SRV_CONN_WRONG_LEN9          = "{ERR_XCHG_SRV_CONN_WRONG_LEN9}"
	ERR_XCHG_SRV_CONN_WRONG_NONCE         = "{ERR_XCHG_SRV_CONN_WRONG_NONCE}"
	ERR_XCHG_SRV_CONN_WRONG_LEN1          = "{ERR_XCHG_SRV_CONN_WRONG_LEN1}"
	ERR_XCHG_SRV_CONN_WRONG_LEN_FN        = "{ERR_XCHG_SRV_CONN_WRONG_LEN_FN}"
	ERR_XCHG_SRV_CONN_AUTH_DATA_LEN4      = "{ERR_XCHG_SRV_CONN_AUTH_DATA_LEN4}"
	ERR_XCHG_SRV_CONN_NOT_IMPL            = "{ERR_XCHG_SRV_CONN_NOT_IMPL}"
	ERR_XCHG_SRV_CONN_AUTH_DATA_LEN_NONCE = "{ERR_XCHG_SRV_CONN_AUTH_DATA_LEN_NONCE}"
	ERR_XCHG_SRV_CONN_AUTH_DATA_LEN_PK    = "{ERR_XCHG_SRV_CONN_AUTH_DATA_LEN_PK}"
	ERR_XCHG_SRV_CONN_AUTH_WRONG_NONCE    = "{ERR_XCHG_SRV_CONN_AUTH_WRONG_NONCE}"

	// Router
	ERR_XCHG_ROUTER_CONFIG_IS_DIRECTORY         = "{ERR_XCHG_ROUTER_CONFIG_IS_DIRECTORY}"
	ERR_XCHG_ROUTER_CONN_WRONG_FRAME_TYPE       = "{ERR_XCHG_ROUTER_CONN_WRONG_FRAME_TYPE}"
	ERR_XCHG_ROUTER_CONN_WRONG_PROTOCOL_VERSION = "{ERR_XCHG_ROUTER_CONN_WRONG_PROTOCOL_VERSION}"
	ERR_XCHG_ROUTER_CONN_WRONG_PUBLIC_KEY_SIZE  = "{ERR_XCHG_ROUTER_CONN_WRONG_PUBLIC_KEY_SIZE}"
	ERR_XCHG_ROUTER_CONN_ENC                    = "{ERR_XCHG_ROUTER_CONN_ENC}"
	ERR_XCHG_ROUTER_CONN_DECR4                  = "{ERR_XCHG_ROUTER_CONN_DECR4}"
	ERR_XCHG_ROUTER_CONN_DECR5                  = "{ERR_XCHG_ROUTER_CONN_DECR5}"
	ERR_XCHG_ROUTER_CONN_NO_ROUTE_TO_PEER       = "{ERR_XCHG_ROUTER_CONN_NO_ROUTE_TO_PEER}"
	ERR_XCHG_ROUTER_SERVER_ALREADY_STARTED      = "{ERR_XCHG_ROUTER_SERVER_ALREADY_STARTED}"
	ERR_XCHG_ROUTER_SERVER_IS_NOT_STARTED       = "{ERR_XCHG_ROUTER_SERVER_IS_NOT_STARTED}"
	ERR_XCHG_ROUTER_ALREADY_STARTED             = "{ERR_XCHG_ROUTER_ALREADY_STARTED}"
	ERR_XCHG_ROUTER_IS_NOT_STARTED              = "{ERR_XCHG_ROUTER_IS_NOT_STARTED}"

	// Other
	ERR_XCHG_NOT_IMPLEMENTED = "{ERR_XCHG_NOT_IMPLEMENTED}"
)
View Source
const AddressBytesSize = 30
View Source
const AddressSize = int((AddressBytesSize * 8) / 5)
View Source
const Base32Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"

Variables

This section is empty.

Functions

func AddressForPublicKey added in v0.0.10

func AddressForPublicKey(publicKey *rsa.PublicKey) string

func AddressForPublicKeyBS added in v0.0.10

func AddressForPublicKeyBS(publicKeyBS []byte) string

func ConnectionPointString added in v0.0.39

func ConnectionPointString(remoteConnectionPoint *net.UDPAddr) string

func DecryptAESGCM added in v0.0.39

func DecryptAESGCM(encryptedMessage []byte, key []byte) (decryptedMessage []byte, err error)

func EncryptAESGCM added in v0.0.39

func EncryptAESGCM(decryptedMessage []byte, key []byte) (encryptedMessage []byte, err error)

func GenerateRSAKey added in v0.0.39

func GenerateRSAKey() (privateKey *rsa.PrivateKey, err error)

func NeedToChangeNode added in v0.0.19

func NeedToChangeNode(err error) bool

Reason to change node

func NeedToMakeSession added in v0.0.19

func NeedToMakeSession(err error) bool

Reason to make session

func NewHost added in v0.0.39

func NewHost(address string) *host

func NewRange added in v0.0.39

func NewRange(prefix string) *rng

func NormalizeAddress added in v0.0.10

func NormalizeAddress(address string) string

func PackBytes added in v0.0.39

func PackBytes(data []byte) []byte

func RSAPublicKeyFromDer added in v0.0.39

func RSAPublicKeyFromDer(publicKeyDer []byte) (publicKey *rsa.PublicKey, err error)

func RSAPublicKeyToDer added in v0.0.39

func RSAPublicKeyToDer(publicKey *rsa.PublicKey) (publicKeyDer []byte)

func UnpackBytes added in v0.0.39

func UnpackBytes(zippedData []byte) (result []byte, err error)

Types

type Network added in v0.0.39

type Network struct {
	Name       string  `json:"name"`
	EthAddress string  `json:"eth_addr"`
	SolAddress string  `json:"sol_addr"`
	Ranges     []*rng  `json:"ranges"`
	Gateways   []*host `json:"gateways"`
	// contains filtered or unexported fields
}

func NewNetwork added in v0.0.39

func NewNetwork() *Network

func NewNetworkDefault added in v0.0.39

func NewNetworkDefault() *Network

func NewNetworkFromBytes added in v0.0.39

func NewNetworkFromBytes(rawContent []byte) (*Network, error)

func NewNetworkFromFile added in v0.0.39

func NewNetworkFromFile(fileName string) (*Network, error)

func NewNetworkFromFileOrCreate added in v0.0.39

func NewNetworkFromFileOrCreate(fileName string) (network *Network)

func NewNetworkFromInternet added in v0.0.39

func NewNetworkFromInternet() *Network

func NewNetworkLocalhost added in v0.0.44

func NewNetworkLocalhost() *Network

func (*Network) AddHostToRange added in v0.0.39

func (c *Network) AddHostToRange(prefix string, address string)

func (*Network) FlatListRandom added in v0.0.44

func (c *Network) FlatListRandom() []string

func (*Network) GetLocalIPs added in v0.0.39

func (c *Network) GetLocalIPs() (result []string)

func (*Network) GetLocalPrefixes added in v0.0.39

func (c *Network) GetLocalPrefixes() []string

func (*Network) GetNodesAddressesByAddress added in v0.0.39

func (c *Network) GetNodesAddressesByAddress(address string) []string

func (*Network) ReloadFromInternet added in v0.0.39

func (c *Network) ReloadFromInternet()

func (*Network) SaveToFile added in v0.0.39

func (c *Network) SaveToFile(fileName string) error

func (*Network) String added in v0.0.39

func (c *Network) String() string

type Nonces added in v0.0.44

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

func NewNonces added in v0.0.44

func NewNonces(size int) *Nonces

func (*Nonces) Check added in v0.0.44

func (c *Nonces) Check(nonce []byte) bool

func (*Nonces) Next added in v0.0.44

func (c *Nonces) Next() [16]byte

type Peer added in v0.0.39

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

func NewPeer added in v0.0.39

func NewPeer(privateKey *rsa.PrivateKey) *Peer

func (*Peer) Call added in v0.0.39

func (c *Peer) Call(remoteAddress string, authData string, function string, data []byte, timeout time.Duration) (result []byte, err error)

func (*Peer) Network added in v0.0.44

func (c *Peer) Network() *Network

func (*Peer) SetProcessor added in v0.0.39

func (c *Peer) SetProcessor(processor ServerProcessor)

func (*Peer) Start added in v0.0.39

func (c *Peer) Start() (err error)

func (*Peer) Stop added in v0.0.39

func (c *Peer) Stop() (err error)

type RemotePeer added in v0.0.39

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

func NewRemotePeer added in v0.0.39

func NewRemotePeer(remoteAddress string, authData string, privateKey *rsa.PrivateKey, network *Network) *RemotePeer

func (*RemotePeer) Call added in v0.0.39

func (c *RemotePeer) Call(conn net.PacketConn, function string, data []byte, timeout time.Duration) (result []byte, err error)

func (*RemotePeer) InternetConnectionPoint added in v0.0.39

func (c *RemotePeer) InternetConnectionPoint() string

func (*RemotePeer) LANConnectionPoint added in v0.0.39

func (c *RemotePeer) LANConnectionPoint() string

func (*RemotePeer) Reset added in v0.0.39

func (c *RemotePeer) Reset()

type ServerProcessor added in v0.0.39

type ServerProcessor interface {
	ServerProcessorAuth(authData []byte) (err error)
	ServerProcessorCall(function string, parameter []byte) (response []byte, err error)
}

type Session added in v0.0.39

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

type SnakeCounter added in v0.0.39

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

func NewSnakeCounter added in v0.0.39

func NewSnakeCounter(size int, initValue int) *SnakeCounter

func (*SnakeCounter) LastProcessed added in v0.0.39

func (c *SnakeCounter) LastProcessed() int

func (*SnakeCounter) Print added in v0.0.39

func (c *SnakeCounter) Print()

func (*SnakeCounter) TestAndDeclare added in v0.0.39

func (c *SnakeCounter) TestAndDeclare(counter int) error

type Transaction

type Transaction struct {
	// Transport Header - 8 bytes
	FrameType byte
	Status    byte
	Reserved2 byte
	Reserved3 byte
	Reserved4 uint32

	// Call header - 32 bytes
	TransactionId uint64
	SessionId     uint64
	Reserved5     uint64
	Offset        uint32
	TotalSize     uint32

	// Data
	Data []byte

	// Execution Result
	BeginDT         time.Time
	ReceivedDataLen int
	Complete        bool
	Result          []byte
	Err             error
}

func NewTransaction

func NewTransaction(frameType byte, transactionId uint64, sessionId uint64, offset int, totalSize int, data []byte) *Transaction

func Parse

func Parse(frame []byte) (tr *Transaction, err error)

func (*Transaction) Marshal added in v0.0.39

func (c *Transaction) Marshal() (result []byte)

func (*Transaction) String added in v0.0.16

func (c *Transaction) String() string

Jump to

Keyboard shortcuts

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