package
0.4.0
Repository: https://github.com/opennhp/opennhp.git
Documentation: pkg.go.dev

# README

NHP-Device架构设计

  1. Device负责NHP报文与消息的转换。Device初始化时需要指定类型和私钥。Device视自身类型只对相应的包进行处理。

  2. 用于承载发送和接收报文的buffer比较大,所以由Device的内存Pool统一发放并回收(如果依赖于Go后台垃圾回收,高并发时会造成大量内存开销)。所以在开发时一定要注意buffer的分配Device.AllocatePoolPacket() 和回收Device.ReleasePoolPacket()

    • 报文buffer回收点位于
      • 发送报文被发送后(本地transaction除外)
      • 接收报文解析完毕时(远程transaction除外)
      • 本地或远程transaction线程停止时
  3. 上层逻辑调用接口SendMsgToPacket将消息转换成加密报文并发送到连接。

  4. 上层逻辑调用接口RecvPacketToMsg将加密报文解析成消息后放入DecryptedMsgQueue队列并等待处理(通常情况)。

    • 特殊情况:如果请求发起方已指定接收通道,解析后的消息会被送到请求方指定的消息通道ResponseMsgCh,而不放进常规消息队列进行排队。
  5. 交互(transaction):一次请求需要等待一次回复的操作称为交互。一次由Device发起的交互请求为本地交互(LocalTransaction),一次由Device接收到的交互请求为远程交互(RemoteTransaction)。由于回应报文需要继承请求报文生成的ChainKey,所以所有的交互分发由Device进行管理。

  6. 连接上下文(ConnectionData):由上层逻辑传入的与连接相关的所有信息,Device在加密消息后将报文发送到连接。一个连接可以进行多个transaction

  7. 在建立发送请求时,需要创建MsgAssembler结构体。

    • Agent和AC必须填写消息类型HeaderType、对端RemoteAddr、对端公钥PeerPk和消息明文Message(如无特殊情况都采用消息压缩)。将填写好的MsgAssembler发给各自的sendMessageRoutine() 即可进行新连接的建立或寻找已存在连接并进行转换后报文的发送。

    • Server必须填写消息类型HeaderType、连接上下文ConnData、对端公钥PeerPk和消息明文Message(如无特殊情况都采用消息压缩)。将填写好的MsgAssembler发给Device.SendMsgToPacket() 即可进行转换后报文的发送。

    • 如果存在交互,可以直接使用上一条获得的 *PacketParserData填入MsgAssembler结构体的PrevParserData字段,从而可以省略填写RemoteAddrConnDataPeerPk

    • 如果请求期待回复数据,需要创建一个接收PacketParserData的通道,并对MsgAssembler结构体的ResponseMsgCh字段赋值。

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
init cipher suite.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Constants

millisecond.
millisecond.
2 seconds.
No description provided by the author
No description provided by the author
second.
millisecond.
packet.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
packet.
packet.
No description provided by the author
No description provided by the author
No description provided by the author
packet.
packet.
packet.
packet.
noise.
noise.
1GB.
second.
second.
millisecond.
server sends ack to ac after receving ac's online status.
No description provided by the author
agent sends to ac/resource for actual ip access.
server replies knock status to agent.
No description provided by the author
ac sends online status to server.
server asks ac for operation.
ac replies server for operation result.
server sends cookie to agent.
agent requests immediate disconnection.
header flags (bit 0 - bit 11).
header flags (bit 0 - bit 11).
cipher scheme combination (bit 11 - bit 15).
agent sends knock to server.
general keepalive packet.
server replies to agent with services and applications result.
agent requests server for listing services and applications.
No description provided by the author
agent requests server for one-time-password.
server sends back ack when agent registers correctly.
agent asks server for registering.
No description provided by the author
agent sends reknock to server.
relay sends relayed packet to server.
No description provided by the author
device.
device.
packet.
protocol.
No description provided by the author
packet.
packet.
packet.
packet.
device.
millisecond.
device.
millisecond.
packet.
block at 2nd attempt.
packet.

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
packet buffer pool.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author