Versions in this module Expand all Collapse all v0 v0.4.0 Sep 4, 2024 Changes in this version + const ACLocalTransactionResponseTimeoutMs + const AgentLocalTransactionResponseTimeoutMs + const AllocateTimeToOverload + const CIPHER_SCHEME_CURVE + const CIPHER_SCHEME_GMSM + const CookieRegenerateTime + const CookieRoundTripTimeMs + const CookieSize + const GCMNonceSize + const GCMTagSize + const HashSize + const HeaderCommonSize + const HeaderSize + const HeaderSizeEx + const InitialChainKeyString + const InitialHashString + const MaxMemoryUsage + const MinimalNSLookupTime + const MinimalPeerAddressHoldTime + const MinimalRecvIntervalMs + const NHP_AAK + const NHP_AC + const NHP_ACC + const NHP_ACK + const NHP_AGENT + const NHP_AOL + const NHP_AOP + const NHP_ART + const NHP_COK + const NHP_EXT + const NHP_FLAG_COMPRESS + const NHP_FLAG_EXTENDEDLENGTH + const NHP_FLAG_SCHEME_GMSM + const NHP_KNK + const NHP_KPL + const NHP_LRT + const NHP_LST + const NHP_NO_DEVICE + const NHP_OTP + const NHP_RAK + const NHP_REG + const NHP_RELAY + const NHP_RKN + const NHP_RLY + const NHP_SERVER + const PacketBufferPoolSize + const PacketBufferSize + const PrivateKeySize + const ProtocolVersionMajor + const ProtocolVersionMinor + const PublicKeyBase64Size + const PublicKeyBase64SizeEx + const PublicKeySize + const PublicKeySizeEx + const RecvQueueSize + const RemoteTransactionProcessTimeoutMs + const SendQueueSize + const ServerLocalTransactionResponseTimeoutMs + const SymmetricKeySize + const ThreatCountBeforeBlock + const TimestampSize + var ErrAEADDecryptionFailed = newError(C.ERR_NHP_AEAD_DECRYPTION_FAILED, "aead decryption failed") + var ErrCipherNotSupported = newError(C.ERR_NHP_CIPHER_NOT_SUPPORTED, "cipher scheme not supported") + var ErrCloseConnection = newError(C.ERR_NHP_CLOSE_CONNECTION, "disengage nhp access immediately") + var ErrCloseDeviceFailed = newError(C.ERR_NHP_CLOSE_DEVICE_FAILED, "attempt to close a non-initialized nhp device") + var ErrCreateDeviceFailed = newError(C.ERR_NHP_CREATE_DEVICE_FAILED, "failed to create nhp device") + var ErrDataCompressionFailed = newError(C.ERR_NHP_DATA_COMPRESSION_FAILED, "data compression failed") + var ErrDataDecompressionFailed = newError(C.ERR_NHP_DATA_DECOMPRESSION_FAILED, "data decompression failed") + var ErrDeviceECDHEphermalFailed = newError(C.ERR_NHP_DEVICE_ECDH_EPHERMAL_FAILED, "device ECDH failed with ephermal") + var ErrDeviceECDHObtainedPeerFailed = newError(C.ERR_NHP_DEVICE_ECDH_OBTAINED_PEER_FAILED, ...) + var ErrDeviceECDHPeerFailed = newError(C.ERR_NHP_DEVICE_ECDH_PEER_FAILED, "device ECDH failed with peer") + var ErrEmptyPeerPublicKey = newError(C.ERR_NHP_EMPTY_PEER_PUBLIC_KEY, "remote peer public key is not set") + var ErrEphermalECDHPeerFailed = newError(C.ERR_NHP_EPHERMAL_ECDH_PEER_FAILED, "ephermal ECDH failed with peer") + var ErrFloodPacketReceived = newError(C.ERR_NHP_FLOOD_PACKET_RECEIVED, "received flood packet, drop") + var ErrHMACCheckFailed = newError(C.ERR_NHP_HMAC_CHECK_FAILED, "HMAC validation failed") + var ErrIdentityTooLong = newError(C.ERR_NHP_IDENTITY_TOO_LONG, "identity exceeds max length") + var ErrIncorrectPacketSize = newError(C.ERR_NHP_INCORRECT_PACKET_SIZE, "incorrect packet size") + var ErrMessageTypeNotMatchDevice = newError(C.ERR_NHP_MESSAGE_TYPE_NOT_MATCH_DEVICE, "message type does not match device") + var ErrNotApplicable = newError(C.ERR_NHP_OPERATION_NOT_APPLICABLE, "operation not applicable") + var ErrPacketSizeExceedsBuffer = newError(C.ERR_NHP_PACKET_SIZE_EXCEEDS_BUFFER, "packet size longer than send buffer") + var ErrPeerIdentityVerificationFailed = newError(C.ERR_NHP_PEER_IDENTITY_VERIFICATION_FAILED, ...) + var ErrReplayPacketReceived = newError(C.ERR_NHP_REPLAY_PACKET_RECEIVED, "received replay packet, drop") + var ErrRuntimePanic = newError(C.ERR_NHP_SDK_RUNTIME_PANIC, "runtime panic encountered") + var ErrServerHMACCheckFailed = newError(C.ERR_NHP_SERVER_HMAC_CHECK_FAILED, "server HMAC validation failed") + var ErrServerOverload = newError(C.ERR_NHP_SERVER_OVERLOAD, "the packet is dropped due to server overload") + var ErrServerRejectWithCookie = newError(C.ERR_NHP_SERVER_REJECT_WITH_COOKIE, ...) + var ErrStalePacketReceived = newError(C.ERR_NHP_STALE_PACKET_RECEIVED, "received stale packet, drop") + var ErrSuccess = newError(C.ERR_NHP_SUCCESS, "") + func AeadFromKey(t GcmTypeEnum, key *[SymmetricKeySize]byte) (aead cipher.AEAD) + func CBCDecryption(t GcmTypeEnum, key *[SymmetricKeySize]byte, ciphertext []byte, inPlace bool) ([]byte, error) + func CBCEncryption(t GcmTypeEnum, key *[SymmetricKeySize]byte, plaintext []byte, inPlace bool) ([]byte, error) + func ErrorToErrorNumber(err error) int + func ErrorToString(err error) string + func HeaderTypeToDeviceType(t int) int + func HeaderTypeToString(t int) string + func IsZero(arr []byte) bool + func NewHash(t HashTypeEnum) (h hash.Hash) + func SetZero(arr []byte) + type CipherSuite struct + EccType EccTypeEnum + GcmType GcmTypeEnum + HashType HashTypeEnum + Scheme int + func NewCipherSuite(scheme int) (ciphers *CipherSuite) + type ConnectionData struct + BlockSignal chan struct{} + CookieStore *CookieStore + Device *Device + InitTime int64 + LastLocalRecvTime int64 + LastLocalSendTime int64 + LastRemoteSendTime int64 + LocalAddr *net.UDPAddr + RecvQueue chan *Packet + RecvThreatCount int32 + RemoteAddr *net.UDPAddr + RemoteTransactionMap map[uint64]*RemoteTransaction + RemoteTransactionMutex sync.Mutex + SendQueue chan *Packet + SetTimeoutSignal chan struct{} + StopSignal chan struct{} + TimeoutMs int + func (c *ConnectionData) AddRemoteTransaction(t *RemoteTransaction) + func (c *ConnectionData) Close() + func (c *ConnectionData) Equal(other *ConnectionData) bool + func (c *ConnectionData) FindRemoteTransaction(id uint64) *RemoteTransaction + func (c *ConnectionData) ForwardInboundPacket(pkt *Packet) + func (c *ConnectionData) ForwardOutboundPacket(pkt *Packet) + func (c *ConnectionData) IsClosed() bool + func (c *ConnectionData) SendBlockSignal() + func (c *ConnectionData) SetTimeout(ms int) + type CookieStore struct + CurrCookie [CookieSize]byte + LastCookieTime int64 + PrevCookie [CookieSize]byte + func (cs *CookieStore) Clear() + func (cs *CookieStore) Set(cookie []byte) + type Device struct + DecryptedMsgQueue chan *PacketParserData + Overload atomic.Bool + func NewDevice(t int, prk []byte, option *DeviceOptions) *Device + func (d *Device) AddLocalTransaction(t *LocalTransaction) + func (d *Device) AddPeer(peer Peer) + func (d *Device) AllocatePoolPacket() *Packet + func (d *Device) CheckRecvHeaderType(t int) bool + func (d *Device) FindLocalTransaction(id uint64) *LocalTransaction + func (d *Device) IsOverload() bool + func (d *Device) IsTransactionRequest(t int) bool + func (d *Device) IsTransactionResponse(t int) bool + func (d *Device) LocalTransactionTimeout() int + func (d *Device) LookupPeer(pk []byte) Peer + func (d *Device) MsgToPacket(md *MsgData) (mad *MsgAssemblerData, err error) + func (d *Device) NextCounterIndex() uint64 + func (d *Device) PacketToMsg(pd *PacketData) (ppd *PacketParserData, err error) + func (d *Device) PublicKeyBase64() string + func (d *Device) PublicKeyExBase64() string + func (d *Device) RecvPacketToMsg(pd *PacketData) + func (d *Device) RecvPrecheck(pkt *Packet) (int, int, error) + func (d *Device) ReleasePoolPacket(pkt *Packet) + func (d *Device) RemoteTransactionTimeout() int + func (d *Device) RemovePeer(pubKey string) + func (d *Device) ResetPeers() + func (d *Device) SendMsgToPacket(md *MsgData) + func (d *Device) SetOption(option DeviceOptions) + func (d *Device) SetOverload(overloaded bool) + func (d *Device) Start() + func (d *Device) Stop() + type DeviceOptions struct + DisableACPeerValidation bool + DisableAgentPeerValidation bool + DisableRelayPeerValidation bool + DisableServerPeerValidation bool + type DeviceTypeEnum = int + type EccTypeEnum int + const ECC_CURVE25519 + const ECC_SM2 + const ECC_UMI + type Ecdh interface + Identity func() []byte + MidPublicKey func() []byte + Name func() string + PrivateKey func() []byte + PrivateKeyBase64 func() string + PublicKey func() []byte + PublicKeyBase64 func() string + SetPrivateKey func(prk []byte) error + SharedSecret func(pbk []byte) []byte + func ECDHFromKey(t EccTypeEnum, prk []byte) (e Ecdh) + func NewECDH(t EccTypeEnum) (e Ecdh) + type Error struct + func ErrorCodeToError(number int) *Error + func (e *Error) Error() string + func (e *Error) ErrorCode() string + func (e *Error) ErrorNumber() int + func (e *Error) SetExtraError(err error) + type GcmTypeEnum int + const GCM_AES256 + const GCM_CHACHA20POLY1305 + const GCM_SM4 + type HashTypeEnum int + const HASH_BLAKE2S + const HASH_SHA256 + const HASH_SM3 + type Header interface + Bytes func() []byte + Counter func() uint64 + EphermeralBytes func() []byte + Flag func() uint16 + HMACBytes func() []byte + IdentityBytes func() []byte + NonceBytes func() []byte + SetCounter func(uint64) + SetFlag func(uint16) + SetTypeAndPayloadSize func(int, int) + SetVersion func(int, int) + Size func() int + StaticBytes func() []byte + TimestampBytes func() []byte + TypeAndPayloadSize func() (int, int) + Version func() (int, int) + type InitiatorScheme interface + CreateMsgAssemblerData func(d *Device, md *MsgData) (mad *MsgAssemblerData, err error) + DeriveMsgAssemblerDataFromPrevParserData func(ppd *PacketParserData, t int, message []byte) (mad *MsgAssemblerData) + EncryptBody func(d *Device, mad *MsgAssemblerData) (err error) + SetPeerPublicKey func(d *Device, mad *MsgAssemblerData, peerPk []byte) (err error) + type LocalTransaction struct + ExternalMsgCh chan *PacketParserData + NextPacketCh chan *Packet + func (t *LocalTransaction) Run() + type MsgAssemblerData struct + BasePacket *Packet + BodyCompress bool + BodySize int + CipherScheme int + Error error + ExternalCookie *[CookieSize]byte + HeaderFlag uint16 + HeaderType int + LocalInitTime int64 + RemotePubKey []byte + ResponseMsgCh chan<- *PacketParserData + TransactionId uint64 + func (mad *MsgAssemblerData) Destroy() + type MsgData struct + CipherScheme int + Compress bool + ConnData *ConnectionData + EncryptedPktCh chan *MsgAssemblerData + ExternalCookie *[CookieSize]byte + ExternalPacket *Packet + HeaderType int + Message []byte + PeerPk []byte + PrevParserData *PacketParserData + RemoteAddr *net.UDPAddr + ResponseMsgCh chan *PacketParserData + TransactionId uint64 + type NhpError interface + Error func() string + ErrorCode func() string + ErrorNumber func() int + type NoiseFactory struct + HashType HashTypeEnum + func (n *NoiseFactory) HMAC1(dst *[HashSize]byte, key, in0 []byte) + func (n *NoiseFactory) HMAC2(dst *[HashSize]byte, key, in0, in1 []byte) + func (n *NoiseFactory) KeyGen1(dst0 *[HashSize]byte, key, input []byte) + func (n *NoiseFactory) KeyGen2(dst0, dst1 *[HashSize]byte, key, input []byte) + func (n *NoiseFactory) KeyGen3(dst0, dst1, dst2 *[HashSize]byte, key, input []byte) + func (n *NoiseFactory) MixHash(dst *[HashSize]byte, key []byte, input []byte) + func (n *NoiseFactory) MixKey(dst *[SymmetricKeySize]byte, key []byte, input []byte) + type Packet struct + Buf *PacketBuffer + Content []byte + HeaderType int + KeepAfterSend bool + PoolAllocated bool + func (pkt *Packet) Counter() uint64 + func (pkt *Packet) Flag() uint16 + func (pkt *Packet) HeaderTypeAndSize() (t int, s int) + type PacketBuffer = [PacketBufferSize]byte + type PacketBufferPool struct + func (bp *PacketBufferPool) Get() *PacketBuffer + func (bp *PacketBufferPool) Init(max uint32) + func (bp *PacketBufferPool) Put(packet *PacketBuffer) + type PacketData struct + BasePacket *Packet + ConnCookieStore *CookieStore + ConnData *ConnectionData + ConnLastRemoteSendTime *int64 + ConnPeerPublicKey *[PublicKeySizeEx]byte + DecryptedMsgCh chan *PacketParserData + InitTime int64 + PrevAssemblerData *MsgAssemblerData + type PacketParserData struct + BodyCompress bool + BodyMessage []byte + BodySize int + CipherScheme int + Ciphers *CipherSuite + ConnCookieStore *CookieStore + ConnData *ConnectionData + ConnLastRemoteSendTime *int64 + ConnPeerPublicKey *[PublicKeySizeEx]byte + Error error + HeaderFlag uint16 + HeaderType int + LocalInitTime int64 + Overload bool + RemotePubKey []byte + SenderIdentity []byte + SenderMidPublicKey []byte + SenderTrxId uint64 + func (ppd *PacketParserData) Destroy() + func (ppd *PacketParserData) IsAllowedAtOverload() bool + type Peer interface + CheckRecvAddress func(currTime int64, currAddr net.Addr) bool + DeviceType func() int + HostOrAddr func() string + IsExpired func() bool + LastRecvTime func() int64 + LastSendTime func() int64 + Name func() string + PublicKey func() []byte + PublicKeyBase64 func() string + RecvAddr func() net.Addr + SendAddr func() net.Addr + UpdateRecv func(currTime int64, currAddr net.Addr) + UpdateSend func(currTime int64) + type RemoteTransaction struct + NextMsgCh chan *MsgData + func (t *RemoteTransaction) Run() + type ResponderScheme interface + CreatePacketParserData func(d *Device, pd *PacketData) (ppd *PacketParserData, err error) + DerivePacketParserDataFromPrevAssemblerData func(mad *MsgAssemblerData, pkt *Packet, initTime int64) (ppd *PacketParserData) + type UdpPeer struct + ExpireTime int64 + Hostname string + Ip string + Port int + PubKeyBase64 string + Type int + func (p *UdpPeer) CheckRecvAddress(currTime int64, currAddr net.Addr) bool + func (p *UdpPeer) CopyResolveStatus(other *UdpPeer) + func (p *UdpPeer) DeviceType() DeviceTypeEnum + func (p *UdpPeer) HostOrAddr() string + func (p *UdpPeer) IsExpired() bool + func (p *UdpPeer) LastRecvTime() int64 + func (p *UdpPeer) LastSendTime() int64 + func (p *UdpPeer) Name() string + func (p *UdpPeer) PublicKey() []byte + func (p *UdpPeer) PublicKeyBase64() string + func (p *UdpPeer) RecvAddr() net.Addr + func (p *UdpPeer) ResolvedIp() string + func (p *UdpPeer) SendAddr() net.Addr + func (p *UdpPeer) UpdateRecv(currTime int64, currAddr net.Addr) + func (p *UdpPeer) UpdateSend(currTime int64)