implemented an api call at /client-conns/id/routes/id/peers/id

This commit is contained in:
hyung-hwan 2024-12-01 17:20:16 +09:00
parent 74fb40d44f
commit 96442bb93a
8 changed files with 200 additions and 76 deletions

View File

@ -54,7 +54,9 @@ type json_out_client_route struct {
type json_out_client_peer struct { type json_out_client_peer struct {
Id uint32 `json:"id"` Id uint32 `json:"id"`
ClientPeerAddr string `json:"client-peer-addr"` ClientPeerAddr string `json:"client-peer-addr"`
ClientLocalAddr string `json:"client-local-addr"`
ServerPeerAddr string `json:"server-peer-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{ jcp = append(jcp, json_out_client_peer{
Id: p.conn_id, Id: p.conn_id,
ClientPeerAddr: p.conn.RemoteAddr().String(), 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() 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 err error
var conn_id string var conn_id string
var route_id string var route_id string
var peer_id string
var conn_nid uint64 var conn_nid uint64
var route_nid uint64 var route_nid uint64
var peer_nid uint64
var je *json.Encoder var je *json.Encoder
var r *ClientRoute var p *ClientPeerConn
c = ctl.c c = ctl.c
je = json.NewEncoder(w) je = json.NewEncoder(w)
conn_id = req.PathValue("conn_id") conn_id = req.PathValue("conn_id")
route_id = req.PathValue("route_id") route_id = req.PathValue("route_id")
peer_id = req.PathValue("peer_id")
conn_nid, err = strconv.ParseUint(conn_id, 10, 32) conn_nid, err = strconv.ParseUint(conn_id, 10, 32)
if err != nil { 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 } if err = je.Encode(json_errmsg{Text: "wrong route id - " + route_id}); err != nil { goto oops }
goto done 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)) p = c.FindClientPeerConnById(uint32(conn_nid), uint32(route_nid), uint32(peer_nid))
if r == nil { if p == nil {
status_code = http.StatusNotFound; w.WriteHeader(status_code) 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 goto done
} }
switch req.Method { switch req.Method {
case http.MethodGet: 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: default:
status_code = http.StatusBadRequest; w.WriteHeader(status_code) status_code = http.StatusBadRequest; w.WriteHeader(status_code)
} }

View File

@ -4,14 +4,16 @@ import "fmt"
import "net" import "net"
import "sync" 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 var cpc ClientPeerConn
cpc.route = r cpc.route = r
cpc.conn = c cpc.conn = c
cpc.conn_id = id 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.stop_req.Store(false)
cpc.server_peer_eof.Store(false)
return &cpc 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.route.cts.psc.Send(MakePeerStoppedPacket(cpc.route.id, cpc.conn_id)) // nothing much to do upon failure. no error check here
cpc.ReqStop() cpc.ReqStop()
cpc.route.RemoveClientPeerConn(cpc)
return nil return nil
} }
@ -56,7 +59,7 @@ func (cpc *ClientPeerConn) ReqStop() {
} }
func (cpc *ClientPeerConn) CloseWrite() { func (cpc *ClientPeerConn) CloseWrite() {
if cpc.server_peer_eof.CompareAndSwap(false, true) { if cpc.pts_eof.CompareAndSwap(false, true) {
if cpc.conn != nil { if cpc.conn != nil {
cpc.conn.CloseWrite() cpc.conn.CloseWrite()
} }

112
client.go
View File

@ -100,9 +100,12 @@ type ClientPeerConn struct {
conn_id uint32 conn_id uint32
conn *net.TCPConn 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_chan chan bool
stop_req atomic.Bool stop_req atomic.Bool
server_peer_eof atomic.Bool
} }
type GuardedPacketStreamClient struct { type GuardedPacketStreamClient struct {
@ -144,6 +147,54 @@ func NewClientRoute(cts *ClientConn, id uint32, addr string, proto ROUTE_PROTO)
return &r 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) { func (r *ClientRoute) RunTask(wg *sync.WaitGroup) {
var err error var err error
@ -187,7 +238,7 @@ func (r *ClientRoute) ReqStop() {
fmt.Printf("*** Sent stop request to Route..\n") 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 err error
var conn net.Conn var conn net.Conn
var real_conn *net.TCPConn var real_conn *net.TCPConn
@ -225,7 +276,7 @@ func (r *ClientRoute) ConnectToPeer(pts_id uint32, wg *sync.WaitGroup) {
goto peer_aborted 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 { if err != nil {
// TODO: logging // TODO: logging
// TODO: make send peer started failure mesage? // TODO: make send peer started failure mesage?
@ -233,7 +284,7 @@ func (r *ClientRoute) ConnectToPeer(pts_id uint32, wg *sync.WaitGroup) {
goto peer_aborted goto peer_aborted
} }
fmt.Printf("STARTED NEW SERVER PEER STAK\n") 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 { if err != nil {
fmt.Printf("CLOSING NEW SERVER PEER STAK - %s\n", err.Error()) fmt.Printf("CLOSING NEW SERVER PEER STAK - %s\n", err.Error())
goto peer_aborted 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) str, ok = event_data.(string)
if !ok { if !ok {
// TODO: internal error // TODO: internal error
fmt.Printf("INTERNAL ERROR. MUST NOT HAPPEN\n")
} else { } else {
var addr *net.TCPAddr var addr *net.TCPAddr
addr, err = net.ResolveTCPAddr("tcp", str) 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: case PACKET_KIND_PEER_STARTED:
fmt.Printf("GOT PEER STARTD . CONENCT TO CLIENT_SIDE PEER\n") fmt.Printf("GOT PEER STARTD . CONENCT TO CLIENT_SIDE PEER\n")
r.ptc_wg.Add(1) var ok bool
go r.ConnectToPeer(pts_id, &r.ptc_wg) 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, pd.RemoteAddrStr, pd.LocalAddrStr, &r.ptc_wg)
}
case PACKET_KIND_PEER_ABORTED: case PACKET_KIND_PEER_ABORTED:
fallthrough fallthrough
@ -650,7 +711,7 @@ fmt.Printf("context doine... error - %s\n", cts.cli.ctx.Err().Error())
var ok bool var ok bool
x, ok = pkt.U.(*Packet_Peer) x, ok = pkt.U.(*Packet_Peer)
if ok { 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 { if err != nil {
// TODO: // TODO:
} else { } 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) 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) 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() { func (c *Client) ReqStop() {
if c.stop_req.CompareAndSwap(false, true) { if c.stop_req.CompareAndSwap(false, true) {
var cts *ClientConn var cts *ClientConn

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.35.1 // protoc-gen-go v1.35.2
// protoc v3.19.6 // protoc v5.28.2
// source: hodu.proto // source: hodu.proto
package hodu package hodu
@ -261,8 +261,10 @@ type PeerDesc struct {
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
RouteId uint32 `protobuf:"varint,1,opt,name=RouteId,proto3" json:"RouteId,omitempty"` RouteId uint32 `protobuf:"varint,1,opt,name=RouteId,proto3" json:"RouteId,omitempty"`
PeerId uint32 `protobuf:"varint,2,opt,name=PeerId,proto3" json:"PeerId,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() { func (x *PeerDesc) Reset() {
@ -309,6 +311,20 @@ func (x *PeerDesc) GetPeerId() uint32 {
return 0 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 { type PeerData struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache 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, 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, 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, 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, 0x52, 0x07, 0x41, 0x64, 0x64, 0x72, 0x53, 0x74, 0x72, 0x22, 0x86, 0x01, 0x0a, 0x08, 0x50, 0x65,
0x72, 0x44, 0x65, 0x73, 0x63, 0x12, 0x18, 0x0a, 0x07, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x49, 0x64, 0x65, 0x72, 0x44, 0x65, 0x73, 0x63, 0x12, 0x18, 0x0a, 0x07, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x49,
0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x49, 0x64, 0x12, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x49, 0x64,
0x16, 0x0a, 0x06, 0x50, 0x65, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x12, 0x16, 0x0a, 0x06, 0x50, 0x65, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d,
0x06, 0x50, 0x65, 0x65, 0x72, 0x49, 0x64, 0x22, 0x50, 0x0a, 0x08, 0x50, 0x65, 0x65, 0x72, 0x44, 0x52, 0x06, 0x50, 0x65, 0x65, 0x72, 0x49, 0x64, 0x12, 0x24, 0x0a, 0x0d, 0x52, 0x65, 0x6d, 0x6f,
0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x49, 0x64, 0x18, 0x01, 0x74, 0x65, 0x41, 0x64, 0x64, 0x72, 0x53, 0x74, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52,
0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x0d, 0x52, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x41, 0x64, 0x64, 0x72, 0x53, 0x74, 0x72, 0x12, 0x22,
0x06, 0x50, 0x65, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x50, 0x0a, 0x0c, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x53, 0x74, 0x72, 0x18, 0x04,
0x65, 0x65, 0x72, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x53,
0x01, 0x28, 0x0c, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x95, 0x01, 0x0a, 0x06, 0x50, 0x61, 0x74, 0x72, 0x22, 0x50, 0x0a, 0x08, 0x50, 0x65, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x12, 0x18,
0x63, 0x6b, 0x65, 0x74, 0x12, 0x20, 0x0a, 0x04, 0x4b, 0x69, 0x6e, 0x64, 0x18, 0x01, 0x20, 0x01, 0x0a, 0x07, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52,
0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x4b, 0x49, 0x4e, 0x44, 0x07, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x50, 0x65, 0x65, 0x72,
0x52, 0x04, 0x4b, 0x69, 0x6e, 0x64, 0x12, 0x22, 0x0a, 0x05, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x18, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x50, 0x65, 0x65, 0x72, 0x49, 0x64,
0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x44, 0x65, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04,
0x63, 0x48, 0x00, 0x52, 0x05, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x12, 0x1f, 0x0a, 0x04, 0x50, 0x65, 0x44, 0x61, 0x74, 0x61, 0x22, 0x95, 0x01, 0x0a, 0x06, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x12,
0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x44, 0x20, 0x0a, 0x04, 0x4b, 0x69, 0x6e, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0c, 0x2e,
0x65, 0x73, 0x63, 0x48, 0x00, 0x52, 0x04, 0x50, 0x65, 0x65, 0x72, 0x12, 0x1f, 0x0a, 0x04, 0x44, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x4b, 0x49, 0x4e, 0x44, 0x52, 0x04, 0x4b, 0x69, 0x6e,
0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x64, 0x12, 0x22, 0x0a, 0x05, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b,
0x44, 0x61, 0x74, 0x61, 0x48, 0x00, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x42, 0x03, 0x0a, 0x01, 0x32, 0x0a, 0x2e, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x44, 0x65, 0x73, 0x63, 0x48, 0x00, 0x52, 0x05,
0x55, 0x2a, 0x2a, 0x0a, 0x0b, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x50, 0x52, 0x4f, 0x54, 0x4f, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x12, 0x1f, 0x0a, 0x04, 0x50, 0x65, 0x65, 0x72, 0x18, 0x03, 0x20,
0x12, 0x07, 0x0a, 0x03, 0x54, 0x43, 0x50, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x54, 0x43, 0x50, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x44, 0x65, 0x73, 0x63, 0x48, 0x00,
0x34, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x54, 0x43, 0x50, 0x36, 0x10, 0x02, 0x2a, 0xba, 0x01, 0x52, 0x04, 0x50, 0x65, 0x65, 0x72, 0x12, 0x1f, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x04,
0x0a, 0x0b, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x4b, 0x49, 0x4e, 0x44, 0x12, 0x09, 0x0a, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x48,
0x05, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, 0x00, 0x12, 0x06, 0x0a, 0x02, 0x4f, 0x4b, 0x10, 0x01, 0x00, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x42, 0x03, 0x0a, 0x01, 0x55, 0x2a, 0x2a, 0x0a, 0x0b,
0x12, 0x0f, 0x0a, 0x0b, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x41, 0x52, 0x54, 0x10, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x50, 0x52, 0x4f, 0x54, 0x4f, 0x12, 0x07, 0x0a, 0x03, 0x54,
0x02, 0x12, 0x0e, 0x0a, 0x0a, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x4f, 0x50, 0x10, 0x43, 0x50, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x54, 0x43, 0x50, 0x34, 0x10, 0x01, 0x12, 0x08,
0x03, 0x12, 0x11, 0x0a, 0x0d, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x41, 0x52, 0x54, 0x0a, 0x04, 0x54, 0x43, 0x50, 0x36, 0x10, 0x02, 0x2a, 0xba, 0x01, 0x0a, 0x0b, 0x50, 0x41, 0x43,
0x45, 0x44, 0x10, 0x04, 0x12, 0x11, 0x0a, 0x0d, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x4b, 0x45, 0x54, 0x5f, 0x4b, 0x49, 0x4e, 0x44, 0x12, 0x09, 0x0a, 0x05, 0x45, 0x52, 0x52, 0x4f,
0x4f, 0x50, 0x50, 0x45, 0x44, 0x10, 0x05, 0x12, 0x10, 0x0a, 0x0c, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x52, 0x10, 0x00, 0x12, 0x06, 0x0a, 0x02, 0x4f, 0x4b, 0x10, 0x01, 0x12, 0x0f, 0x0a, 0x0b, 0x52,
0x53, 0x54, 0x41, 0x52, 0x54, 0x45, 0x44, 0x10, 0x06, 0x12, 0x10, 0x0a, 0x0c, 0x50, 0x45, 0x45, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x41, 0x52, 0x54, 0x10, 0x02, 0x12, 0x0e, 0x0a, 0x0a,
0x52, 0x5f, 0x53, 0x54, 0x4f, 0x50, 0x50, 0x45, 0x44, 0x10, 0x07, 0x12, 0x10, 0x0a, 0x0c, 0x50, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x4f, 0x50, 0x10, 0x03, 0x12, 0x11, 0x0a, 0x0d,
0x45, 0x45, 0x52, 0x5f, 0x41, 0x42, 0x4f, 0x52, 0x54, 0x45, 0x44, 0x10, 0x08, 0x12, 0x0c, 0x0a, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x41, 0x52, 0x54, 0x45, 0x44, 0x10, 0x04, 0x12,
0x08, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x45, 0x4f, 0x46, 0x10, 0x09, 0x12, 0x0d, 0x0a, 0x09, 0x50, 0x11, 0x0a, 0x0d, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x4f, 0x50, 0x50, 0x45, 0x44,
0x45, 0x45, 0x52, 0x5f, 0x44, 0x41, 0x54, 0x41, 0x10, 0x0a, 0x32, 0x49, 0x0a, 0x04, 0x48, 0x6f, 0x10, 0x05, 0x12, 0x10, 0x0a, 0x0c, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x53, 0x54, 0x41, 0x52, 0x54,
0x64, 0x75, 0x12, 0x19, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x53, 0x65, 0x65, 0x64, 0x12, 0x05, 0x2e, 0x45, 0x44, 0x10, 0x06, 0x12, 0x10, 0x0a, 0x0c, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x53, 0x54, 0x4f,
0x53, 0x65, 0x65, 0x64, 0x1a, 0x05, 0x2e, 0x53, 0x65, 0x65, 0x64, 0x22, 0x00, 0x12, 0x26, 0x0a, 0x50, 0x50, 0x45, 0x44, 0x10, 0x07, 0x12, 0x10, 0x0a, 0x0c, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x41,
0x0c, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x07, 0x2e, 0x42, 0x4f, 0x52, 0x54, 0x45, 0x44, 0x10, 0x08, 0x12, 0x0c, 0x0a, 0x08, 0x50, 0x45, 0x45, 0x52,
0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x1a, 0x07, 0x2e, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x22, 0x5f, 0x45, 0x4f, 0x46, 0x10, 0x09, 0x12, 0x0d, 0x0a, 0x09, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x44,
0x00, 0x28, 0x01, 0x30, 0x01, 0x42, 0x08, 0x5a, 0x06, 0x2e, 0x2f, 0x68, 0x6f, 0x64, 0x75, 0x62, 0x41, 0x54, 0x41, 0x10, 0x0a, 0x32, 0x49, 0x0a, 0x04, 0x48, 0x6f, 0x64, 0x75, 0x12, 0x19, 0x0a,
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 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 ( var (

View File

@ -29,6 +29,8 @@ message RouteDesc {
message PeerDesc { message PeerDesc {
uint32 RouteId = 1; uint32 RouteId = 1;
uint32 PeerId = 2; uint32 PeerId = 2;
string RemoteAddrStr = 3;
string LocalAddrStr = 4;
}; };
message PeerData { message PeerData {

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT. // Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions: // versions:
// - protoc-gen-go-grpc v1.5.1 // - protoc-gen-go-grpc v1.5.1
// - protoc v3.19.6 // - protoc v5.28.2
// source: hodu.proto // source: hodu.proto
package hodu package hodu

View File

@ -24,10 +24,10 @@ func MakeRouteStoppedPacket(route_id uint32, proto ROUTE_PROTO) *Packet {
U: &Packet_Route{Route: &RouteDesc{RouteId: route_id, Proto: proto}}} 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 // the connection from a peer to the server has been established
return &Packet{Kind: PACKET_KIND_PEER_STARTED, 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}},
} }
} }

View File

@ -52,7 +52,7 @@ func (spc *ServerPeerConn) RunTask(wg *sync.WaitGroup) {
defer wg.Done() defer wg.Done()
pss = spc.route.cts.pss 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 { if err != nil {
// TODO: include route id and conn id in the error message // TODO: include route id and conn id in the error message
fmt.Printf("unable to send start-pts - %s\n", err.Error()) fmt.Printf("unable to send start-pts - %s\n", err.Error())