implemented an api call at /client-conns/id/routes/id/peers/id
This commit is contained in:
parent
74fb40d44f
commit
96442bb93a
@ -54,7 +54,9 @@ type json_out_client_route struct {
|
||||
type json_out_client_peer struct {
|
||||
Id uint32 `json:"id"`
|
||||
ClientPeerAddr string `json:"client-peer-addr"`
|
||||
ClientLocalAddr string `json:"client-local-addr"`
|
||||
ServerPeerAddr string `json:"server-peer-addr"`
|
||||
ServerLocalAddr string `json:"server-local-addr"`
|
||||
}
|
||||
// ------------------------------------
|
||||
|
||||
@ -471,7 +473,9 @@ func (ctl *client_ctl_client_conns_id_routes_id_peers) ServeHTTP(w http.Response
|
||||
jcp = append(jcp, json_out_client_peer{
|
||||
Id: p.conn_id,
|
||||
ClientPeerAddr: p.conn.RemoteAddr().String(),
|
||||
//ServerPeerAddr: r.server_peer,
|
||||
ClientLocalAddr: p.conn.LocalAddr().String(),
|
||||
ServerPeerAddr: p.pts_raddr,
|
||||
ServerLocalAddr: p.pts_laddr,
|
||||
})
|
||||
}
|
||||
r.ptc_mtx.Unlock()
|
||||
@ -501,16 +505,19 @@ func (ctl *client_ctl_client_conns_id_routes_id_peers_id) ServeHTTP(w http.Respo
|
||||
var err error
|
||||
var conn_id string
|
||||
var route_id string
|
||||
var peer_id string
|
||||
var conn_nid uint64
|
||||
var route_nid uint64
|
||||
var peer_nid uint64
|
||||
var je *json.Encoder
|
||||
var r *ClientRoute
|
||||
var p *ClientPeerConn
|
||||
|
||||
c = ctl.c
|
||||
je = json.NewEncoder(w)
|
||||
|
||||
conn_id = req.PathValue("conn_id")
|
||||
route_id = req.PathValue("route_id")
|
||||
peer_id = req.PathValue("peer_id")
|
||||
|
||||
conn_nid, err = strconv.ParseUint(conn_id, 10, 32)
|
||||
if err != nil {
|
||||
@ -524,16 +531,35 @@ func (ctl *client_ctl_client_conns_id_routes_id_peers_id) ServeHTTP(w http.Respo
|
||||
if err = je.Encode(json_errmsg{Text: "wrong route id - " + route_id}); err != nil { goto oops }
|
||||
goto done
|
||||
}
|
||||
peer_nid, err = strconv.ParseUint(peer_id, 10, 32)
|
||||
if err != nil {
|
||||
status_code = http.StatusBadRequest; w.WriteHeader(status_code)
|
||||
if err = je.Encode(json_errmsg{Text: "wrong peer id - " + peer_id}); err != nil { goto oops }
|
||||
goto done
|
||||
}
|
||||
|
||||
r = c.FindClientRouteById(uint32(conn_nid), uint32(route_nid))
|
||||
if r == nil {
|
||||
p = c.FindClientPeerConnById(uint32(conn_nid), uint32(route_nid), uint32(peer_nid))
|
||||
if p == nil {
|
||||
status_code = http.StatusNotFound; w.WriteHeader(status_code)
|
||||
if err = je.Encode(json_errmsg{Text: "non-existent connection/route id - " + conn_id + "/" + route_id}); err != nil { goto oops }
|
||||
if err = je.Encode(json_errmsg{Text: "non-existent connection/route/peer id - " + conn_id + "/" + route_id + "/" + peer_id}); err != nil { goto oops }
|
||||
goto done
|
||||
}
|
||||
|
||||
switch req.Method {
|
||||
case http.MethodGet:
|
||||
var jcp *json_out_client_peer
|
||||
|
||||
jcp = &json_out_client_peer{
|
||||
Id: p.conn_id,
|
||||
ClientPeerAddr: p.conn.RemoteAddr().String(),
|
||||
ClientLocalAddr: p.conn.LocalAddr().String(),
|
||||
ServerPeerAddr: p.pts_raddr,
|
||||
ServerLocalAddr: p.pts_laddr,
|
||||
}
|
||||
|
||||
status_code = http.StatusOK; w.WriteHeader(status_code)
|
||||
if err = je.Encode(jcp); err != nil { goto oops }
|
||||
|
||||
default:
|
||||
status_code = http.StatusBadRequest; w.WriteHeader(status_code)
|
||||
}
|
||||
|
@ -4,14 +4,16 @@ import "fmt"
|
||||
import "net"
|
||||
import "sync"
|
||||
|
||||
func NewClientPeerConn(r *ClientRoute, c *net.TCPConn, id uint32) *ClientPeerConn {
|
||||
func NewClientPeerConn(r *ClientRoute, c *net.TCPConn, id uint32, pts_raddr string, pts_laddr string) *ClientPeerConn {
|
||||
var cpc ClientPeerConn
|
||||
|
||||
cpc.route = r
|
||||
cpc.conn = c
|
||||
cpc.conn_id = id
|
||||
cpc.pts_raddr = pts_raddr
|
||||
cpc.pts_laddr = pts_laddr
|
||||
cpc.pts_eof.Store(false)
|
||||
cpc.stop_req.Store(false)
|
||||
cpc.server_peer_eof.Store(false)
|
||||
|
||||
return &cpc
|
||||
}
|
||||
@ -43,6 +45,7 @@ fmt.Printf("CONNECTION ESTABLISHED TO PEER... ABOUT TO READ DATA...\n")
|
||||
cpc.route.cts.psc.Send(MakePeerStoppedPacket(cpc.route.id, cpc.conn_id)) // nothing much to do upon failure. no error check here
|
||||
|
||||
cpc.ReqStop()
|
||||
cpc.route.RemoveClientPeerConn(cpc)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -56,7 +59,7 @@ func (cpc *ClientPeerConn) ReqStop() {
|
||||
}
|
||||
|
||||
func (cpc *ClientPeerConn) CloseWrite() {
|
||||
if cpc.server_peer_eof.CompareAndSwap(false, true) {
|
||||
if cpc.pts_eof.CompareAndSwap(false, true) {
|
||||
if cpc.conn != nil {
|
||||
cpc.conn.CloseWrite()
|
||||
}
|
||||
|
110
client.go
110
client.go
@ -100,9 +100,12 @@ type ClientPeerConn struct {
|
||||
conn_id uint32
|
||||
conn *net.TCPConn
|
||||
|
||||
pts_laddr string // server-local addreess of the server-side peer
|
||||
pts_raddr string // address of the server-side peer
|
||||
pts_eof atomic.Bool
|
||||
|
||||
stop_chan chan bool
|
||||
stop_req atomic.Bool
|
||||
server_peer_eof atomic.Bool
|
||||
}
|
||||
|
||||
type GuardedPacketStreamClient struct {
|
||||
@ -144,6 +147,54 @@ func NewClientRoute(cts *ClientConn, id uint32, addr string, proto ROUTE_PROTO)
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r *ClientRoute) AddNewClientPeerConn(c *net.TCPConn, pts_id uint32, pts_raddr string, pts_laddr string) (*ClientPeerConn, error) {
|
||||
var ptc *ClientPeerConn
|
||||
|
||||
r.ptc_mtx.Lock()
|
||||
defer r.ptc_mtx.Unlock()
|
||||
|
||||
ptc = NewClientPeerConn(r, c, pts_id, pts_raddr, pts_laddr)
|
||||
r.ptc_map[ptc.conn_id] = ptc
|
||||
|
||||
return ptc, nil
|
||||
}
|
||||
|
||||
func (r *ClientRoute) RemoveClientPeerConn(ptc *ClientPeerConn) error {
|
||||
var c *ClientPeerConn
|
||||
var ok bool
|
||||
|
||||
r.ptc_mtx.Lock()
|
||||
c, ok = r.ptc_map[ptc.conn_id]
|
||||
if !ok {
|
||||
r.ptc_mtx.Unlock()
|
||||
return fmt.Errorf("non-existent peer id - %d", ptc.conn_id)
|
||||
}
|
||||
if c != ptc {
|
||||
r.ptc_mtx.Unlock()
|
||||
return fmt.Errorf("non-existent peer id - %d", ptc.conn_id)
|
||||
}
|
||||
delete(r.ptc_map, ptc.conn_id)
|
||||
r.ptc_mtx.Unlock()
|
||||
|
||||
ptc.ReqStop()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *ClientRoute) FindClientPeerConnById(conn_id uint32) *ClientPeerConn {
|
||||
var c *ClientPeerConn
|
||||
var ok bool
|
||||
|
||||
r.ptc_mtx.Lock()
|
||||
defer r.ptc_mtx.Unlock()
|
||||
|
||||
c, ok = r.ptc_map[conn_id]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func (r *ClientRoute) RunTask(wg *sync.WaitGroup) {
|
||||
var err error
|
||||
|
||||
@ -187,7 +238,7 @@ func (r *ClientRoute) ReqStop() {
|
||||
fmt.Printf("*** Sent stop request to Route..\n")
|
||||
}
|
||||
|
||||
func (r *ClientRoute) ConnectToPeer(pts_id uint32, wg *sync.WaitGroup) {
|
||||
func (r *ClientRoute) ConnectToPeer(pts_id uint32, pts_raddr string, pts_laddr string, wg *sync.WaitGroup) {
|
||||
var err error
|
||||
var conn net.Conn
|
||||
var real_conn *net.TCPConn
|
||||
@ -225,7 +276,7 @@ func (r *ClientRoute) ConnectToPeer(pts_id uint32, wg *sync.WaitGroup) {
|
||||
goto peer_aborted
|
||||
}
|
||||
|
||||
ptc, err = r.AddNewClientPeerConn(real_conn, pts_id)
|
||||
ptc, err = r.AddNewClientPeerConn(real_conn, pts_id, pts_raddr, pts_laddr)
|
||||
if err != nil {
|
||||
// TODO: logging
|
||||
// TODO: make send peer started failure mesage?
|
||||
@ -233,7 +284,7 @@ func (r *ClientRoute) ConnectToPeer(pts_id uint32, wg *sync.WaitGroup) {
|
||||
goto peer_aborted
|
||||
}
|
||||
fmt.Printf("STARTED NEW SERVER PEER STAK\n")
|
||||
err = r.cts.psc.Send(MakePeerStartedPacket(r.id, ptc.conn_id))
|
||||
err = r.cts.psc.Send(MakePeerStartedPacket(r.id, ptc.conn_id, real_conn.RemoteAddr().String(), real_conn.LocalAddr().String()))
|
||||
if err != nil {
|
||||
fmt.Printf("CLOSING NEW SERVER PEER STAK - %s\n", err.Error())
|
||||
goto peer_aborted
|
||||
@ -302,6 +353,7 @@ func (r *ClientRoute) ReportEvent(pts_id uint32, event_type PACKET_KIND, event_d
|
||||
str, ok = event_data.(string)
|
||||
if !ok {
|
||||
// TODO: internal error
|
||||
fmt.Printf("INTERNAL ERROR. MUST NOT HAPPEN\n")
|
||||
} else {
|
||||
var addr *net.TCPAddr
|
||||
addr, err = net.ResolveTCPAddr("tcp", str)
|
||||
@ -317,8 +369,17 @@ func (r *ClientRoute) ReportEvent(pts_id uint32, event_type PACKET_KIND, event_d
|
||||
|
||||
case PACKET_KIND_PEER_STARTED:
|
||||
fmt.Printf("GOT PEER STARTD . CONENCT TO CLIENT_SIDE PEER\n")
|
||||
var ok bool
|
||||
var pd *PeerDesc
|
||||
|
||||
pd, ok = event_data.(*PeerDesc)
|
||||
if !ok {
|
||||
// TODO: internal error
|
||||
fmt.Printf("INTERNAL ERROR. MUST NOT HAPPEN\n")
|
||||
} else {
|
||||
r.ptc_wg.Add(1)
|
||||
go r.ConnectToPeer(pts_id, &r.ptc_wg)
|
||||
go r.ConnectToPeer(pts_id, pd.RemoteAddrStr, pd.LocalAddrStr, &r.ptc_wg)
|
||||
}
|
||||
|
||||
case PACKET_KIND_PEER_ABORTED:
|
||||
fallthrough
|
||||
@ -650,7 +711,7 @@ fmt.Printf("context doine... error - %s\n", cts.cli.ctx.Err().Error())
|
||||
var ok bool
|
||||
x, ok = pkt.U.(*Packet_Peer)
|
||||
if ok {
|
||||
err = cts.ReportEvent(x.Peer.RouteId, x.Peer.PeerId, PACKET_KIND_PEER_STARTED, nil)
|
||||
err = cts.ReportEvent(x.Peer.RouteId, x.Peer.PeerId, PACKET_KIND_PEER_STARTED, x.Peer)
|
||||
if err != nil {
|
||||
// TODO:
|
||||
} else {
|
||||
@ -753,19 +814,6 @@ func (cts *ClientConn) ReportEvent (route_id uint32, pts_id uint32, event_type P
|
||||
|
||||
return r.ReportEvent(pts_id, event_type, event_data)
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
func (r *ClientRoute) AddNewClientPeerConn(c *net.TCPConn, pts_id uint32) (*ClientPeerConn, error) {
|
||||
var ptc *ClientPeerConn
|
||||
|
||||
r.ptc_mtx.Lock()
|
||||
defer r.ptc_mtx.Unlock()
|
||||
|
||||
ptc = NewClientPeerConn(r, c, pts_id)
|
||||
r.ptc_map[ptc.conn_id] = ptc
|
||||
|
||||
return ptc, nil
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
@ -934,6 +982,30 @@ func (c *Client) FindClientRouteById(conn_id uint32, route_id uint32) *ClientRou
|
||||
return cts.FindClientRouteById(route_id)
|
||||
}
|
||||
|
||||
func (c *Client) FindClientPeerConnById(conn_id uint32, route_id uint32, peer_id uint32) *ClientPeerConn {
|
||||
var cts *ClientConn
|
||||
var r* ClientRoute
|
||||
var ok bool
|
||||
|
||||
c.cts_mtx.Lock()
|
||||
defer c.cts_mtx.Unlock()
|
||||
|
||||
cts, ok = c.cts_map[conn_id]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
cts.route_mtx.Lock()
|
||||
defer cts.route_mtx.Unlock()
|
||||
|
||||
r, ok = cts.route_map[route_id]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
return r.FindClientPeerConnById(peer_id)
|
||||
}
|
||||
|
||||
func (c *Client) ReqStop() {
|
||||
if c.stop_req.CompareAndSwap(false, true) {
|
||||
var cts *ClientConn
|
||||
|
105
hodu.pb.go
105
hodu.pb.go
@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.35.1
|
||||
// protoc v3.19.6
|
||||
// protoc-gen-go v1.35.2
|
||||
// protoc v5.28.2
|
||||
// source: hodu.proto
|
||||
|
||||
package hodu
|
||||
@ -263,6 +263,8 @@ type PeerDesc struct {
|
||||
|
||||
RouteId uint32 `protobuf:"varint,1,opt,name=RouteId,proto3" json:"RouteId,omitempty"`
|
||||
PeerId uint32 `protobuf:"varint,2,opt,name=PeerId,proto3" json:"PeerId,omitempty"`
|
||||
RemoteAddrStr string `protobuf:"bytes,3,opt,name=RemoteAddrStr,proto3" json:"RemoteAddrStr,omitempty"`
|
||||
LocalAddrStr string `protobuf:"bytes,4,opt,name=LocalAddrStr,proto3" json:"LocalAddrStr,omitempty"`
|
||||
}
|
||||
|
||||
func (x *PeerDesc) Reset() {
|
||||
@ -309,6 +311,20 @@ func (x *PeerDesc) GetPeerId() uint32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *PeerDesc) GetRemoteAddrStr() string {
|
||||
if x != nil {
|
||||
return x.RemoteAddrStr
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *PeerDesc) GetLocalAddrStr() string {
|
||||
if x != nil {
|
||||
return x.LocalAddrStr
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type PeerData struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@ -484,46 +500,51 @@ var file_hodu_proto_rawDesc = []byte{
|
||||
0x72, 0x6f, 0x74, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x52, 0x4f, 0x55,
|
||||
0x54, 0x45, 0x5f, 0x50, 0x52, 0x4f, 0x54, 0x4f, 0x52, 0x05, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x12,
|
||||
0x18, 0x0a, 0x07, 0x41, 0x64, 0x64, 0x72, 0x53, 0x74, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09,
|
||||
0x52, 0x07, 0x41, 0x64, 0x64, 0x72, 0x53, 0x74, 0x72, 0x22, 0x3c, 0x0a, 0x08, 0x50, 0x65, 0x65,
|
||||
0x72, 0x44, 0x65, 0x73, 0x63, 0x12, 0x18, 0x0a, 0x07, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x49, 0x64,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x49, 0x64, 0x12,
|
||||
0x16, 0x0a, 0x06, 0x50, 0x65, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52,
|
||||
0x06, 0x50, 0x65, 0x65, 0x72, 0x49, 0x64, 0x22, 0x50, 0x0a, 0x08, 0x50, 0x65, 0x65, 0x72, 0x44,
|
||||
0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x49, 0x64, 0x18, 0x01,
|
||||
0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x49, 0x64, 0x12, 0x16, 0x0a,
|
||||
0x06, 0x50, 0x65, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x50,
|
||||
0x65, 0x65, 0x72, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20,
|
||||
0x01, 0x28, 0x0c, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x95, 0x01, 0x0a, 0x06, 0x50, 0x61,
|
||||
0x63, 0x6b, 0x65, 0x74, 0x12, 0x20, 0x0a, 0x04, 0x4b, 0x69, 0x6e, 0x64, 0x18, 0x01, 0x20, 0x01,
|
||||
0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x4b, 0x49, 0x4e, 0x44,
|
||||
0x52, 0x04, 0x4b, 0x69, 0x6e, 0x64, 0x12, 0x22, 0x0a, 0x05, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x18,
|
||||
0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x44, 0x65, 0x73,
|
||||
0x63, 0x48, 0x00, 0x52, 0x05, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x12, 0x1f, 0x0a, 0x04, 0x50, 0x65,
|
||||
0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x44,
|
||||
0x65, 0x73, 0x63, 0x48, 0x00, 0x52, 0x04, 0x50, 0x65, 0x65, 0x72, 0x12, 0x1f, 0x0a, 0x04, 0x44,
|
||||
0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x50, 0x65, 0x65, 0x72,
|
||||
0x44, 0x61, 0x74, 0x61, 0x48, 0x00, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x42, 0x03, 0x0a, 0x01,
|
||||
0x55, 0x2a, 0x2a, 0x0a, 0x0b, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x50, 0x52, 0x4f, 0x54, 0x4f,
|
||||
0x12, 0x07, 0x0a, 0x03, 0x54, 0x43, 0x50, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x54, 0x43, 0x50,
|
||||
0x34, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x54, 0x43, 0x50, 0x36, 0x10, 0x02, 0x2a, 0xba, 0x01,
|
||||
0x0a, 0x0b, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x4b, 0x49, 0x4e, 0x44, 0x12, 0x09, 0x0a,
|
||||
0x05, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, 0x00, 0x12, 0x06, 0x0a, 0x02, 0x4f, 0x4b, 0x10, 0x01,
|
||||
0x12, 0x0f, 0x0a, 0x0b, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x41, 0x52, 0x54, 0x10,
|
||||
0x02, 0x12, 0x0e, 0x0a, 0x0a, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x4f, 0x50, 0x10,
|
||||
0x03, 0x12, 0x11, 0x0a, 0x0d, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x41, 0x52, 0x54,
|
||||
0x45, 0x44, 0x10, 0x04, 0x12, 0x11, 0x0a, 0x0d, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54,
|
||||
0x4f, 0x50, 0x50, 0x45, 0x44, 0x10, 0x05, 0x12, 0x10, 0x0a, 0x0c, 0x50, 0x45, 0x45, 0x52, 0x5f,
|
||||
0x53, 0x54, 0x41, 0x52, 0x54, 0x45, 0x44, 0x10, 0x06, 0x12, 0x10, 0x0a, 0x0c, 0x50, 0x45, 0x45,
|
||||
0x52, 0x5f, 0x53, 0x54, 0x4f, 0x50, 0x50, 0x45, 0x44, 0x10, 0x07, 0x12, 0x10, 0x0a, 0x0c, 0x50,
|
||||
0x45, 0x45, 0x52, 0x5f, 0x41, 0x42, 0x4f, 0x52, 0x54, 0x45, 0x44, 0x10, 0x08, 0x12, 0x0c, 0x0a,
|
||||
0x08, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x45, 0x4f, 0x46, 0x10, 0x09, 0x12, 0x0d, 0x0a, 0x09, 0x50,
|
||||
0x45, 0x45, 0x52, 0x5f, 0x44, 0x41, 0x54, 0x41, 0x10, 0x0a, 0x32, 0x49, 0x0a, 0x04, 0x48, 0x6f,
|
||||
0x64, 0x75, 0x12, 0x19, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x53, 0x65, 0x65, 0x64, 0x12, 0x05, 0x2e,
|
||||
0x53, 0x65, 0x65, 0x64, 0x1a, 0x05, 0x2e, 0x53, 0x65, 0x65, 0x64, 0x22, 0x00, 0x12, 0x26, 0x0a,
|
||||
0x0c, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x07, 0x2e,
|
||||
0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x1a, 0x07, 0x2e, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x22,
|
||||
0x00, 0x28, 0x01, 0x30, 0x01, 0x42, 0x08, 0x5a, 0x06, 0x2e, 0x2f, 0x68, 0x6f, 0x64, 0x75, 0x62,
|
||||
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x52, 0x07, 0x41, 0x64, 0x64, 0x72, 0x53, 0x74, 0x72, 0x22, 0x86, 0x01, 0x0a, 0x08, 0x50, 0x65,
|
||||
0x65, 0x72, 0x44, 0x65, 0x73, 0x63, 0x12, 0x18, 0x0a, 0x07, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x49,
|
||||
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x49, 0x64,
|
||||
0x12, 0x16, 0x0a, 0x06, 0x50, 0x65, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d,
|
||||
0x52, 0x06, 0x50, 0x65, 0x65, 0x72, 0x49, 0x64, 0x12, 0x24, 0x0a, 0x0d, 0x52, 0x65, 0x6d, 0x6f,
|
||||
0x74, 0x65, 0x41, 0x64, 0x64, 0x72, 0x53, 0x74, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x0d, 0x52, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x41, 0x64, 0x64, 0x72, 0x53, 0x74, 0x72, 0x12, 0x22,
|
||||
0x0a, 0x0c, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x53, 0x74, 0x72, 0x18, 0x04,
|
||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x53,
|
||||
0x74, 0x72, 0x22, 0x50, 0x0a, 0x08, 0x50, 0x65, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x12, 0x18,
|
||||
0x0a, 0x07, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52,
|
||||
0x07, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x50, 0x65, 0x65, 0x72,
|
||||
0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x50, 0x65, 0x65, 0x72, 0x49, 0x64,
|
||||
0x12, 0x12, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04,
|
||||
0x44, 0x61, 0x74, 0x61, 0x22, 0x95, 0x01, 0x0a, 0x06, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x12,
|
||||
0x20, 0x0a, 0x04, 0x4b, 0x69, 0x6e, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0c, 0x2e,
|
||||
0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x4b, 0x49, 0x4e, 0x44, 0x52, 0x04, 0x4b, 0x69, 0x6e,
|
||||
0x64, 0x12, 0x22, 0x0a, 0x05, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b,
|
||||
0x32, 0x0a, 0x2e, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x44, 0x65, 0x73, 0x63, 0x48, 0x00, 0x52, 0x05,
|
||||
0x52, 0x6f, 0x75, 0x74, 0x65, 0x12, 0x1f, 0x0a, 0x04, 0x50, 0x65, 0x65, 0x72, 0x18, 0x03, 0x20,
|
||||
0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x44, 0x65, 0x73, 0x63, 0x48, 0x00,
|
||||
0x52, 0x04, 0x50, 0x65, 0x65, 0x72, 0x12, 0x1f, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x04,
|
||||
0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x48,
|
||||
0x00, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x42, 0x03, 0x0a, 0x01, 0x55, 0x2a, 0x2a, 0x0a, 0x0b,
|
||||
0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x50, 0x52, 0x4f, 0x54, 0x4f, 0x12, 0x07, 0x0a, 0x03, 0x54,
|
||||
0x43, 0x50, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x54, 0x43, 0x50, 0x34, 0x10, 0x01, 0x12, 0x08,
|
||||
0x0a, 0x04, 0x54, 0x43, 0x50, 0x36, 0x10, 0x02, 0x2a, 0xba, 0x01, 0x0a, 0x0b, 0x50, 0x41, 0x43,
|
||||
0x4b, 0x45, 0x54, 0x5f, 0x4b, 0x49, 0x4e, 0x44, 0x12, 0x09, 0x0a, 0x05, 0x45, 0x52, 0x52, 0x4f,
|
||||
0x52, 0x10, 0x00, 0x12, 0x06, 0x0a, 0x02, 0x4f, 0x4b, 0x10, 0x01, 0x12, 0x0f, 0x0a, 0x0b, 0x52,
|
||||
0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x41, 0x52, 0x54, 0x10, 0x02, 0x12, 0x0e, 0x0a, 0x0a,
|
||||
0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x4f, 0x50, 0x10, 0x03, 0x12, 0x11, 0x0a, 0x0d,
|
||||
0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x41, 0x52, 0x54, 0x45, 0x44, 0x10, 0x04, 0x12,
|
||||
0x11, 0x0a, 0x0d, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x4f, 0x50, 0x50, 0x45, 0x44,
|
||||
0x10, 0x05, 0x12, 0x10, 0x0a, 0x0c, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x53, 0x54, 0x41, 0x52, 0x54,
|
||||
0x45, 0x44, 0x10, 0x06, 0x12, 0x10, 0x0a, 0x0c, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x53, 0x54, 0x4f,
|
||||
0x50, 0x50, 0x45, 0x44, 0x10, 0x07, 0x12, 0x10, 0x0a, 0x0c, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x41,
|
||||
0x42, 0x4f, 0x52, 0x54, 0x45, 0x44, 0x10, 0x08, 0x12, 0x0c, 0x0a, 0x08, 0x50, 0x45, 0x45, 0x52,
|
||||
0x5f, 0x45, 0x4f, 0x46, 0x10, 0x09, 0x12, 0x0d, 0x0a, 0x09, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x44,
|
||||
0x41, 0x54, 0x41, 0x10, 0x0a, 0x32, 0x49, 0x0a, 0x04, 0x48, 0x6f, 0x64, 0x75, 0x12, 0x19, 0x0a,
|
||||
0x07, 0x47, 0x65, 0x74, 0x53, 0x65, 0x65, 0x64, 0x12, 0x05, 0x2e, 0x53, 0x65, 0x65, 0x64, 0x1a,
|
||||
0x05, 0x2e, 0x53, 0x65, 0x65, 0x64, 0x22, 0x00, 0x12, 0x26, 0x0a, 0x0c, 0x50, 0x61, 0x63, 0x6b,
|
||||
0x65, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x07, 0x2e, 0x50, 0x61, 0x63, 0x6b, 0x65,
|
||||
0x74, 0x1a, 0x07, 0x2e, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x22, 0x00, 0x28, 0x01, 0x30, 0x01,
|
||||
0x42, 0x08, 0x5a, 0x06, 0x2e, 0x2f, 0x68, 0x6f, 0x64, 0x75, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
|
||||
0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -29,6 +29,8 @@ message RouteDesc {
|
||||
message PeerDesc {
|
||||
uint32 RouteId = 1;
|
||||
uint32 PeerId = 2;
|
||||
string RemoteAddrStr = 3;
|
||||
string LocalAddrStr = 4;
|
||||
};
|
||||
|
||||
message PeerData {
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.5.1
|
||||
// - protoc v3.19.6
|
||||
// - protoc v5.28.2
|
||||
// source: hodu.proto
|
||||
|
||||
package hodu
|
||||
|
@ -24,10 +24,10 @@ func MakeRouteStoppedPacket(route_id uint32, proto ROUTE_PROTO) *Packet {
|
||||
U: &Packet_Route{Route: &RouteDesc{RouteId: route_id, Proto: proto}}}
|
||||
}
|
||||
|
||||
func MakePeerStartedPacket(route_id uint32, peer_id uint32) *Packet {
|
||||
func MakePeerStartedPacket(route_id uint32, peer_id uint32, remote_addr string, local_addr string) *Packet {
|
||||
// the connection from a peer to the server has been established
|
||||
return &Packet{Kind: PACKET_KIND_PEER_STARTED,
|
||||
U: &Packet_Peer{Peer: &PeerDesc{RouteId: route_id, PeerId: peer_id}},
|
||||
U: &Packet_Peer{Peer: &PeerDesc{RouteId: route_id, PeerId: peer_id, RemoteAddrStr: remote_addr, LocalAddrStr: local_addr}},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ func (spc *ServerPeerConn) RunTask(wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
|
||||
pss = spc.route.cts.pss
|
||||
err = pss.Send(MakePeerStartedPacket(spc.route.id, spc.conn_id))
|
||||
err = pss.Send(MakePeerStartedPacket(spc.route.id, spc.conn_id, spc.conn.RemoteAddr().String(), spc.conn.LocalAddr().String()))
|
||||
if err != nil {
|
||||
// TODO: include route id and conn id in the error message
|
||||
fmt.Printf("unable to send start-pts - %s\n", err.Error())
|
||||
|
Loading…
x
Reference in New Issue
Block a user