xchg

package
v0.2.7 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	NetworkContainerDefault             = "" /* 1156-byte string literal not displayed */
	NetworkContainerEncryptedPrivateKey = "" /* 1664-byte string literal not displayed */
	NetworkContainerPublicKey           = "" /* 392-byte string literal not displayed */
	NetworkContainerFileNetwork         = "network.json"
	NetworkContainerFileSignature       = "signature.base64"
)
View Source
const (
	UDP_PORT          = 8484
	INPUT_BUFFER_SIZE = 1024 * 1024
)
View Source
const (
	PEER_UDP_START_PORT = 42000
	PEER_UDP_END_PORT   = 42500
)
View Source
const (
	TransactionHeaderSize = 128

	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"
View Source
const (
	INTERNAL_ERROR = "#internal_error#"
)

Variables

This section is empty.

Functions

func AddressBSForPublicKey added in v0.1.0

func AddressBSForPublicKey(publicKey *rsa.PublicKey) []byte

func AddressBSForPublicKeyBS added in v0.1.0

func AddressBSForPublicKeyBS(publicKeyBS []byte) []byte

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 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 NetworkContainerCreateKey added in v0.1.2

func NetworkContainerCreateKey(privateKeyPassword string) (encryptedPrivateKeyBase64 string, publicKeyBase64 string, err error)

func NetworkContainerMake added in v0.1.2

func NetworkContainerMake(network *Network, encryptedPrivateKeyBase64 string, privateKeyPassword string) (resultZipFile []byte, err error)

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"`
	Timestamp     int64    `json:"timestamp"`
	InitialPoints []string `json:"initial_points"`
	Ranges        []*rng   `json:"ranges"`
	// contains filtered or unexported fields
}

func NetworkContainerLoad added in v0.1.2

func NetworkContainerLoad(zipFileBS []byte, publicKeyBase64 string) (network *Network, err error)

func NetworkContainerLoadDefault added in v0.1.2

func NetworkContainerLoadDefault(zipFileBS []byte) (network *Network, err error)

func NetworkContainerLoadFromInternet added in v0.1.5

func NetworkContainerLoadFromInternet() (network *Network, err error)

func NetworkContainerLoadStaticDefault added in v0.1.5

func NetworkContainerLoadStaticDefault() (network *Network, err error)

func NewNetwork added in v0.0.39

func NewNetwork() *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 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) GetLocalNodes added in v0.2.7

func (c *Network) GetLocalNodes() []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) IsLocalNode added in v0.2.7

func (c *Network) IsLocalNode(nodeAddress string) bool

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(enableLocalRouter bool) (err error)

func (*Peer) Stop added in v0.0.39

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

type PeerContext added in v0.2.2

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

type PeerHttp added in v0.1.1

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

func NewPeerHttp added in v0.1.1

func NewPeerHttp(network *Network, routerHost string) *PeerHttp

func (*PeerHttp) Post added in v0.1.1

func (c *PeerHttp) Post(httpClient *http.Client, url, contentType string, body io.Reader, host string) (resp *http.Response, err error)

func (*PeerHttp) Start added in v0.1.1

func (c *PeerHttp) Start(peerProcessor PeerProcessor, localAddressBS []byte) (err error)

func (*PeerHttp) Stop added in v0.1.1

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

type PeerProcessor added in v0.1.1

type PeerProcessor interface {
	// contains filtered or unexported methods
}

type PeerTransport added in v0.2.2

type PeerTransport interface {
	Start(peerProcessor PeerProcessor, localAddressBS []byte) error
	Stop() 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(peerContext PeerContext, function string, data []byte, timeout time.Duration) (result []byte, err error)

func (*RemotePeer) RemoteAddress added in v0.1.0

func (c *RemotePeer) RemoteAddress() string

func (*RemotePeer) Reset added in v0.0.39

func (c *RemotePeer) Reset()

type RemotePeerHttp added in v0.1.0

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

func NewRemotePeerHttp added in v0.1.0

func NewRemotePeerHttp() *RemotePeerHttp

func (*RemotePeerHttp) Check added in v0.1.0

func (c *RemotePeerHttp) Check(peerContext PeerContext, frame20 *Transaction, network *Network, remotePublicKeyExists bool) error

func (*RemotePeerHttp) DeclareError added in v0.2.2

func (c *RemotePeerHttp) DeclareError(peerContext PeerContext, sentViaTransportMap map[string]struct{})

func (*RemotePeerHttp) Id added in v0.2.2

func (c *RemotePeerHttp) Id() string

func (*RemotePeerHttp) Post added in v0.1.0

func (c *RemotePeerHttp) Post(url, contentType string, body io.Reader, host string) (resp *http.Response, err error)

func (*RemotePeerHttp) Send added in v0.1.0

func (c *RemotePeerHttp) Send(peerContext PeerContext, network *Network, tr *Transaction) (err error)

func (*RemotePeerHttp) SetRemoteUDPAddress added in v0.2.2

func (c *RemotePeerHttp) SetRemoteUDPAddress(udpAddress *net.UDPAddr)

type RemotePeerTcp added in v0.2.2

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

func NewRemotePeerTcp added in v0.2.2

func NewRemotePeerTcp() *RemotePeerTcp

func (*RemotePeerTcp) Check added in v0.2.2

func (c *RemotePeerTcp) Check(peerContext PeerContext, frame20 *Transaction, network *Network, remotePublicKeyExists bool) error

func (*RemotePeerTcp) DeclareError added in v0.2.2

func (c *RemotePeerTcp) DeclareError(peerContext PeerContext, sentViaTransportMap map[string]struct{})

func (*RemotePeerTcp) Id added in v0.2.2

func (c *RemotePeerTcp) Id() string

func (*RemotePeerTcp) Send added in v0.2.2

func (c *RemotePeerTcp) Send(peerContext PeerContext, network *Network, tr *Transaction) error

func (*RemotePeerTcp) SetRemoteUDPAddress added in v0.2.2

func (c *RemotePeerTcp) SetRemoteUDPAddress(udpAddress *net.UDPAddr)

type RemotePeerTransport added in v0.2.2

type RemotePeerTransport interface {
	Id() string
	Check(peerContext PeerContext, frame20 *Transaction, network *Network, remotePublicKeyExists bool) error
	DeclareError(peerContext PeerContext, sentViaTransportMap map[string]struct{})
	Send(peerContext PeerContext, network *Network, tr *Transaction) error
	SetRemoteUDPAddress(udpAddress *net.UDPAddr)
}

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
	Length    uint32 // 0
	CRC       uint32 // 4
	FrameType byte   // 8

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

	// 30 bytes - Source Address
	SrcAddress [AddressBytesSize]byte
	// 30 bytes - Source Address
	DestAddress [AddressBytesSize]byte

	// 28 bytes
	Appendix [28]byte

	// Data
	Data []byte

	FromLocalNode bool

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

func NewTransaction

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

func Parse

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

func (*Transaction) AppendReceivedData added in v0.1.2

func (c *Transaction) AppendReceivedData(transaction *Transaction)

func (*Transaction) DestAddressString added in v0.2.2

func (c *Transaction) DestAddressString() string

func (*Transaction) Marshal added in v0.0.39

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

func (*Transaction) SrcAddressString added in v0.2.2

func (c *Transaction) SrcAddressString() string

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