2024-11-23 12:30:23 +09:00
|
|
|
package hodu
|
2024-11-12 22:59:37 +09:00
|
|
|
|
2024-12-09 22:41:23 +09:00
|
|
|
type ConnId uint64
|
|
|
|
type RouteId uint32
|
|
|
|
type PeerId uint32
|
|
|
|
|
|
|
|
func MakeRouteStartPacket(route_id RouteId, proto ROUTE_PROTO, addr string, svcnet string) *Packet {
|
2024-11-12 22:59:37 +09:00
|
|
|
return &Packet{
|
|
|
|
Kind: PACKET_KIND_ROUTE_START,
|
2024-12-09 22:41:23 +09:00
|
|
|
U: &Packet_Route{Route: &RouteDesc{RouteId: uint32(route_id), ServiceProto: proto, TargetAddrStr: addr, ServiceNetStr: svcnet}}}
|
2024-11-12 22:59:37 +09:00
|
|
|
}
|
|
|
|
|
2024-12-09 22:41:23 +09:00
|
|
|
func MakeRouteStopPacket(route_id RouteId, proto ROUTE_PROTO, addr string, svcnet string) *Packet {
|
2024-11-24 20:39:51 +09:00
|
|
|
return &Packet{
|
|
|
|
Kind: PACKET_KIND_ROUTE_STOP,
|
2024-12-09 22:41:23 +09:00
|
|
|
U: &Packet_Route{Route: &RouteDesc{RouteId: uint32(route_id), ServiceProto: proto, TargetAddrStr: addr, ServiceNetStr: svcnet}}}
|
2024-11-24 20:39:51 +09:00
|
|
|
}
|
|
|
|
|
2024-12-09 22:41:23 +09:00
|
|
|
func MakeRouteStartedPacket(route_id RouteId, proto ROUTE_PROTO, addr string, svcnet string) *Packet {
|
2024-11-12 22:59:37 +09:00
|
|
|
// the connection from a peer to the server has been established
|
|
|
|
return &Packet{Kind: PACKET_KIND_ROUTE_STARTED,
|
2024-12-09 22:41:23 +09:00
|
|
|
U: &Packet_Route{Route: &RouteDesc{RouteId: uint32(route_id), ServiceProto: proto, TargetAddrStr: addr, ServiceNetStr: svcnet}}}
|
2024-11-12 22:59:37 +09:00
|
|
|
}
|
|
|
|
|
2024-12-09 22:41:23 +09:00
|
|
|
func MakeRouteStoppedPacket(route_id RouteId, proto ROUTE_PROTO, addr string, svcnet string) *Packet {
|
2024-11-12 22:59:37 +09:00
|
|
|
// the connection from a peer to the server has been established
|
|
|
|
return &Packet{Kind: PACKET_KIND_ROUTE_STOPPED,
|
2024-12-09 22:41:23 +09:00
|
|
|
U: &Packet_Route{Route: &RouteDesc{RouteId: uint32(route_id), ServiceProto: proto, TargetAddrStr: addr, ServiceNetStr: svcnet}}}
|
2024-11-12 22:59:37 +09:00
|
|
|
}
|
|
|
|
|
2024-12-09 22:41:23 +09:00
|
|
|
func MakePeerStartedPacket(route_id RouteId, peer_id PeerId, remote_addr string, local_addr string) *Packet {
|
2024-11-12 22:59:37 +09:00
|
|
|
// the connection from a peer to the server has been established
|
|
|
|
return &Packet{Kind: PACKET_KIND_PEER_STARTED,
|
2024-12-09 22:41:23 +09:00
|
|
|
U: &Packet_Peer{Peer: &PeerDesc{RouteId: uint32(route_id), PeerId: uint32(peer_id), RemoteAddrStr: remote_addr, LocalAddrStr: local_addr}},
|
2024-11-12 22:59:37 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-09 22:41:23 +09:00
|
|
|
func MakePeerStoppedPacket(route_id RouteId, peer_id PeerId, remote_addr string, local_addr string) *Packet {
|
2024-11-12 22:59:37 +09:00
|
|
|
return &Packet{Kind: PACKET_KIND_PEER_STOPPED,
|
2024-12-09 22:41:23 +09:00
|
|
|
U: &Packet_Peer{Peer: &PeerDesc{RouteId: uint32(route_id), PeerId: uint32(peer_id), RemoteAddrStr: remote_addr, LocalAddrStr: local_addr}},
|
2024-12-03 20:28:04 +09:00
|
|
|
}
|
2024-11-12 22:59:37 +09:00
|
|
|
}
|
|
|
|
|
2024-12-09 22:41:23 +09:00
|
|
|
func MakePeerAbortedPacket(route_id RouteId, peer_id PeerId, remote_addr string, local_addr string) *Packet {
|
2024-11-20 00:48:02 +09:00
|
|
|
return &Packet{Kind: PACKET_KIND_PEER_ABORTED,
|
2024-12-09 22:41:23 +09:00
|
|
|
U: &Packet_Peer{Peer: &PeerDesc{RouteId: uint32(route_id), PeerId: uint32(peer_id), RemoteAddrStr: remote_addr, LocalAddrStr: local_addr}},
|
2024-12-05 01:26:44 +09:00
|
|
|
}
|
2024-11-20 00:48:02 +09:00
|
|
|
}
|
|
|
|
|
2024-12-09 22:41:23 +09:00
|
|
|
func MakePeerEofPacket(route_id RouteId, peer_id PeerId) *Packet {
|
2024-11-18 22:25:59 +09:00
|
|
|
return &Packet{Kind: PACKET_KIND_PEER_EOF,
|
2024-12-09 22:41:23 +09:00
|
|
|
U: &Packet_Peer{Peer: &PeerDesc{RouteId: uint32(route_id), PeerId: uint32(peer_id)}}}
|
2024-11-12 22:59:37 +09:00
|
|
|
}
|
|
|
|
|
2024-12-09 22:41:23 +09:00
|
|
|
func MakePeerDataPacket(route_id RouteId, peer_id PeerId, data []byte) *Packet {
|
2024-11-12 22:59:37 +09:00
|
|
|
return &Packet{Kind: PACKET_KIND_PEER_DATA,
|
2024-12-09 22:41:23 +09:00
|
|
|
U: &Packet_Data{Data: &PeerData{RouteId: uint32(route_id), PeerId: uint32(peer_id), Data: data}}}
|
2024-11-12 22:59:37 +09:00
|
|
|
}
|