added fields to hold creation time in various structures
This commit is contained in:
parent
f1f74ed48d
commit
3714138656
@ -23,6 +23,7 @@ type json_out_server_conn struct {
|
||||
ServerAddr string `json:"server-addr"`
|
||||
ClientAddr string `json:"client-addr"`
|
||||
ClientToken string `json:"client-token"`
|
||||
CreatedMilli int64 `json:"created-milli"`
|
||||
Routes []json_out_server_route `json:"routes"`
|
||||
}
|
||||
|
||||
@ -33,6 +34,7 @@ type json_out_server_route struct {
|
||||
ServerPeerOption string `json:"server-peer-option"`
|
||||
ServerPeerSvcAddr string `json:"server-peer-svc-addr"` // actual listening address
|
||||
ServerPeerSvcNet string `json:"server-peer-svc-net"`
|
||||
CreatedMilli int64 `json:"created-milli"`
|
||||
}
|
||||
|
||||
type json_out_server_peer struct {
|
||||
@ -41,6 +43,7 @@ type json_out_server_peer struct {
|
||||
ServerLocalAddr string `json:"server-local-addr"`
|
||||
ClientPeerAddr string `json:"client-peer-addr"`
|
||||
ClientLocalAddr string `json:"client-local-addr"`
|
||||
CreatedMilli int64 `json:"created-milli"`
|
||||
}
|
||||
|
||||
type json_out_server_stats struct {
|
||||
@ -213,6 +216,7 @@ func (ctl *server_ctl_server_conns) ServeHTTP(w http.ResponseWriter, req *http.R
|
||||
ServerPeerSvcAddr: r.SvcAddr.String(),
|
||||
ServerPeerSvcNet: r.SvcPermNet.String(),
|
||||
ServerPeerOption: r.SvcOption.String(),
|
||||
CreatedMilli: r.Created.UnixMilli(),
|
||||
})
|
||||
}
|
||||
cts.route_mtx.Unlock()
|
||||
@ -221,6 +225,7 @@ func (ctl *server_ctl_server_conns) ServeHTTP(w http.ResponseWriter, req *http.R
|
||||
ClientAddr: cts.RemoteAddr.String(),
|
||||
ServerAddr: cts.LocalAddr.String(),
|
||||
ClientToken: cts.ClientToken.Get(),
|
||||
CreatedMilli: cts.Created.UnixMilli(),
|
||||
Routes: jsp,
|
||||
})
|
||||
}
|
||||
@ -284,6 +289,7 @@ func (ctl *server_ctl_server_conns_id) ServeHTTP(w http.ResponseWriter, req *htt
|
||||
ServerPeerSvcAddr: r.SvcAddr.String(),
|
||||
ServerPeerSvcNet: r.SvcPermNet.String(),
|
||||
ServerPeerOption: r.SvcOption.String(),
|
||||
CreatedMilli: r.Created.UnixMilli(),
|
||||
})
|
||||
}
|
||||
cts.route_mtx.Unlock()
|
||||
@ -292,6 +298,7 @@ func (ctl *server_ctl_server_conns_id) ServeHTTP(w http.ResponseWriter, req *htt
|
||||
ClientAddr: cts.RemoteAddr.String(),
|
||||
ServerAddr: cts.LocalAddr.String(),
|
||||
ClientToken: cts.ClientToken.Get(),
|
||||
CreatedMilli: cts.Created.UnixMilli(),
|
||||
Routes: jsp,
|
||||
}
|
||||
|
||||
@ -353,6 +360,7 @@ func (ctl *server_ctl_server_conns_id_routes) ServeHTTP(w http.ResponseWriter, r
|
||||
ServerPeerSvcAddr: r.SvcAddr.String(),
|
||||
ServerPeerSvcNet: r.SvcPermNet.String(),
|
||||
ServerPeerOption: r.SvcOption.String(),
|
||||
CreatedMilli: r.Created.UnixMilli(),
|
||||
})
|
||||
}
|
||||
cts.route_mtx.Unlock()
|
||||
@ -440,6 +448,7 @@ func (ctl *server_ctl_server_conns_id_routes_id) ServeHTTP(w http.ResponseWriter
|
||||
ServerPeerSvcAddr: r.SvcAddr.String(),
|
||||
ServerPeerSvcNet: r.SvcPermNet.String(),
|
||||
ServerPeerOption: r.SvcOption.String(),
|
||||
CreatedMilli: r.Created.UnixMilli(),
|
||||
})
|
||||
if err != nil { goto oops }
|
||||
|
||||
@ -501,8 +510,9 @@ func (ctl *server_ctl_server_conns_id_routes_id_peers) ServeHTTP(w http.Response
|
||||
Id: p.conn_id,
|
||||
ServerPeerAddr: p.conn.RemoteAddr().String(),
|
||||
ServerLocalAddr: p.conn.LocalAddr().String(),
|
||||
ClientPeerAddr: p.client_peer_raddr,
|
||||
ClientLocalAddr: p.client_peer_laddr,
|
||||
ClientPeerAddr: p.client_peer_raddr.Get(),
|
||||
ClientLocalAddr: p.client_peer_laddr.Get(),
|
||||
CreatedMilli: p.Created.UnixMilli(),
|
||||
})
|
||||
}
|
||||
r.pts_mtx.Unlock()
|
||||
@ -558,8 +568,9 @@ func (ctl *server_ctl_server_conns_id_routes_id_peers_id) ServeHTTP(w http.Respo
|
||||
Id: p.conn_id,
|
||||
ServerPeerAddr: p.conn.RemoteAddr().String(),
|
||||
ServerLocalAddr: p.conn.LocalAddr().String(),
|
||||
ClientPeerAddr: p.client_peer_raddr,
|
||||
ClientLocalAddr: p.client_peer_laddr,
|
||||
ClientPeerAddr: p.client_peer_raddr.Get(),
|
||||
ClientLocalAddr: p.client_peer_laddr.Get(),
|
||||
CreatedMilli: p.Created.UnixMilli(),
|
||||
}
|
||||
|
||||
status_code = WriteJsonRespHeader(w, http.StatusOK)
|
||||
|
@ -13,6 +13,7 @@ type ServerPeerConn struct {
|
||||
route *ServerRoute
|
||||
conn_id PeerId
|
||||
conn *net.TCPConn
|
||||
Created time.Time
|
||||
|
||||
stop_chan chan bool
|
||||
stop_req atomic.Bool
|
||||
@ -21,8 +22,8 @@ type ServerPeerConn struct {
|
||||
client_peer_started atomic.Bool
|
||||
client_peer_stopped atomic.Bool
|
||||
client_peer_eof atomic.Bool
|
||||
client_peer_laddr string
|
||||
client_peer_raddr string
|
||||
client_peer_laddr Atom[string]
|
||||
client_peer_raddr Atom[string]
|
||||
}
|
||||
|
||||
func NewServerPeerConn(r *ServerRoute, c *net.TCPConn, id PeerId) *ServerPeerConn {
|
||||
@ -31,6 +32,7 @@ func NewServerPeerConn(r *ServerRoute, c *net.TCPConn, id PeerId) *ServerPeerCon
|
||||
spc.route = r
|
||||
spc.conn = c
|
||||
spc.conn_id = id
|
||||
spc.Created = time.Now()
|
||||
|
||||
spc.stop_chan = make(chan bool, 8)
|
||||
spc.stop_req.Store(false)
|
||||
@ -143,6 +145,15 @@ done:
|
||||
done_without_stop:
|
||||
spc.ReqStop()
|
||||
spc.route.RemoveServerPeerConn(spc)
|
||||
|
||||
spc.route.Cts.S.bulletin.Enqueue(
|
||||
&ServerEvent{
|
||||
Kind: SERVER_EVENT_PEER_DELETED,
|
||||
Data: &ServerEventPeerDeleted {
|
||||
Conn: spc.route.Cts.Id, Route: spc.route.Id, Peer: spc.conn_id,
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (spc *ServerPeerConn) ReqStop() {
|
||||
@ -170,17 +181,33 @@ func (spc *ServerPeerConn) ReportPacket(packet_type PACKET_KIND, event_data inte
|
||||
pd, ok = event_data.(*PeerDesc)
|
||||
if !ok {
|
||||
// something wrong. leave it unknown.
|
||||
spc.client_peer_laddr = ""
|
||||
spc.client_peer_raddr = ""
|
||||
spc.client_peer_laddr.Set("")
|
||||
spc.client_peer_raddr.Set("")
|
||||
} else {
|
||||
spc.client_peer_laddr = pd.LocalAddrStr
|
||||
spc.client_peer_raddr = pd.RemoteAddrStr
|
||||
spc.client_peer_laddr.Set(pd.LocalAddrStr)
|
||||
spc.client_peer_raddr.Set(pd.RemoteAddrStr)
|
||||
}
|
||||
|
||||
if spc.client_peer_started.CompareAndSwap(false, true) {
|
||||
spc.client_peer_status_chan <- true
|
||||
}
|
||||
|
||||
spc.route.Cts.S.bulletin.Enqueue(
|
||||
&ServerEvent{
|
||||
Kind: SERVER_EVENT_PEER_UPDATED,
|
||||
Data: &ServerEventPeerAdded{
|
||||
Conn: spc.route.Cts.Id,
|
||||
Route: spc.route.Id,
|
||||
Peer: spc.conn_id,
|
||||
ServerPeerAddr: spc.conn.RemoteAddr().String(),
|
||||
ServerLocalAddr: spc.conn.LocalAddr().String(),
|
||||
ClientPeerAddr: spc.client_peer_raddr.Get(),
|
||||
ClientLocalAddr: spc.client_peer_laddr.Get(),
|
||||
CreatedMilli: spc.Created.UnixMilli(),
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
case PACKET_KIND_PEER_ABORTED:
|
||||
spc.ReqStop()
|
||||
|
||||
|
43
server.go
43
server.go
@ -70,10 +70,13 @@ type ServerConfig struct {
|
||||
type ServerEventKind int
|
||||
const (
|
||||
SERVER_EVENT_CONN_ADDED = iota
|
||||
SERVER_EVENT_CONN_UPDATED
|
||||
SERVER_EVENT_CONN_DELETED
|
||||
SERVER_EVENT_ROUTE_ADDED
|
||||
SERVER_EVENT_ROUTE_UPDATED
|
||||
SERVER_EVENT_ROUTE_DELETED
|
||||
SERVER_EVENT_PEER_ADDED
|
||||
SERVER_EVENT_PEER_UPDATED
|
||||
SERVER_EVENT_PEER_DELETED
|
||||
)
|
||||
|
||||
@ -87,6 +90,7 @@ type ServerEventConnAdded struct {
|
||||
ServerAddr string `json:"server-addr"`
|
||||
ClientAddr string `json:"client-addr"`
|
||||
ClientToken string `json:"client-token"`
|
||||
CreatedMilli int64 `json:"created-milli"`
|
||||
}
|
||||
|
||||
type ServerEventConnDeleted struct {
|
||||
@ -101,6 +105,7 @@ type ServerEventRouteAdded struct {
|
||||
ServerPeerOption string `json:"server-peer-option"`
|
||||
ServerPeerSvcAddr string `json:"server-peer-svc-addr"`
|
||||
ServerPeerSvcNet string `json:"server-peer-svc-net"`
|
||||
CreatedMilli int64 `json:"created-milli"`
|
||||
}
|
||||
|
||||
type ServerEventRouteDeleted struct {
|
||||
@ -108,6 +113,23 @@ type ServerEventRouteDeleted struct {
|
||||
Route RouteId `json:"route-id"`
|
||||
}
|
||||
|
||||
type ServerEventPeerAdded struct {
|
||||
Conn ConnId `json:"conn-id"`
|
||||
Route RouteId `json:"route-id"`
|
||||
Peer PeerId `json:"peer-id"`
|
||||
ServerPeerAddr string `json:"server-peer-addr"`
|
||||
ServerLocalAddr string `json:"server-local-addr"`
|
||||
ClientPeerAddr string `json:"client-peer-addr"`
|
||||
ClientLocalAddr string `json:"client-local-addr"`
|
||||
CreatedMilli int64 `json:"created-milli"`
|
||||
}
|
||||
|
||||
type ServerEventPeerDeleted struct {
|
||||
Conn ConnId `json:"conn-id"`
|
||||
Route RouteId `json:"route-id"`
|
||||
Peer PeerId `json:"peer-id"`
|
||||
}
|
||||
|
||||
type ServerEventBulletin = Bulletin[*ServerEvent]
|
||||
type ServerEventSubscription = BulletinSubscription[*ServerEvent]
|
||||
|
||||
@ -176,6 +198,7 @@ type ServerConn struct {
|
||||
S *Server
|
||||
Id ConnId
|
||||
Sid string // for logging
|
||||
Created time.Time
|
||||
ClientToken Atom[string] // provided by client
|
||||
|
||||
RemoteAddr net.Addr // client address that created this structure
|
||||
@ -194,6 +217,7 @@ type ServerConn struct {
|
||||
type ServerRoute struct {
|
||||
Cts *ServerConn
|
||||
Id RouteId
|
||||
Created time.Time
|
||||
|
||||
svc_l *net.TCPListener
|
||||
SvcAddr *net.TCPAddr // actual listening address
|
||||
@ -270,6 +294,7 @@ func NewServerRoute(cts *ServerConn, id RouteId, option RouteOption, ptc_addr st
|
||||
|
||||
r.Cts = cts
|
||||
r.Id = id
|
||||
r.Created = time.Now()
|
||||
r.svc_l = l
|
||||
r.SvcAddr = svcaddr
|
||||
r.SvcReqAddr = svc_requested_addr
|
||||
@ -320,6 +345,21 @@ func (r *ServerRoute) AddNewServerPeerConn(c *net.TCPConn) (*ServerPeerConn, err
|
||||
r.pts_map[pts.conn_id] = pts
|
||||
r.Cts.S.stats.peers.Add(1)
|
||||
|
||||
r.Cts.S.bulletin.Enqueue(
|
||||
&ServerEvent{
|
||||
Kind: SERVER_EVENT_PEER_ADDED,
|
||||
Data: &ServerEventPeerAdded{
|
||||
Conn: r.Cts.Id,
|
||||
Route: r.Id,
|
||||
Peer: pts.conn_id,
|
||||
ServerPeerAddr: pts.conn.RemoteAddr().String(),
|
||||
ServerLocalAddr: pts.conn.LocalAddr().String(),
|
||||
ClientPeerAddr: pts.client_peer_raddr.Get(),
|
||||
ClientLocalAddr: pts.client_peer_laddr.Get(),
|
||||
CreatedMilli: pts.Created.UnixMilli(),
|
||||
},
|
||||
},
|
||||
)
|
||||
return pts, nil
|
||||
}
|
||||
|
||||
@ -537,6 +577,7 @@ func (cts *ServerConn) AddNewServerRoute(route_id RouteId, proto RouteOption, pt
|
||||
ServerPeerSvcAddr: r.SvcAddr.String(),
|
||||
ServerPeerSvcNet: r.SvcPermNet.String(),
|
||||
ServerPeerOption: r.SvcOption.String(),
|
||||
CreatedMilli: r.Created.UnixMilli(),
|
||||
},
|
||||
},
|
||||
)
|
||||
@ -996,6 +1037,7 @@ func (s *Server) PacketStream(strm Hodu_PacketStreamServer) error {
|
||||
ServerAddr: cts.LocalAddr.String(),
|
||||
ClientAddr: cts.RemoteAddr.String(),
|
||||
ClientToken: cts.ClientToken.Get(),
|
||||
CreatedMilli: cts.Created.UnixMilli(),
|
||||
},
|
||||
},
|
||||
)
|
||||
@ -1713,6 +1755,7 @@ func (s *Server) AddNewServerConn(remote_addr *net.Addr, local_addr *net.Addr, p
|
||||
var ok bool
|
||||
|
||||
cts.S = s
|
||||
cts.Created = time.Now()
|
||||
cts.route_map = make(ServerRouteMap)
|
||||
cts.RemoteAddr = *remote_addr
|
||||
cts.LocalAddr = *local_addr
|
||||
|
Loading…
x
Reference in New Issue
Block a user