stored client-side peer info to ServerConnPeer when PEER_STARTED is received
This commit is contained in:
parent
f2536a0acc
commit
be7f4f4da5
@ -1267,6 +1267,7 @@ func (c *Client) wrap_http_handler(handler ClientHttpHandler) http.Handler {
|
|||||||
if handler.Cors(req) {
|
if handler.Cors(req) {
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
w.Header().Set("Access-Control-Allow-Headers", "*")
|
w.Header().Set("Access-Control-Allow-Headers", "*")
|
||||||
|
w.Header().Set("Access-Control-Allow-Methods", "*")
|
||||||
}
|
}
|
||||||
if req.Method == http.MethodOptions {
|
if req.Method == http.MethodOptions {
|
||||||
status_code = WriteEmptyRespHeader(w, http.StatusOK)
|
status_code = WriteEmptyRespHeader(w, http.StatusOK)
|
||||||
|
@ -33,10 +33,10 @@ type json_out_server_route struct {
|
|||||||
|
|
||||||
type json_out_server_peer struct {
|
type json_out_server_peer struct {
|
||||||
Id PeerId `json:"id"`
|
Id PeerId `json:"id"`
|
||||||
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"`
|
ServerLocalAddr string `json:"server-local-addr"`
|
||||||
|
ClientPeerAddr string `json:"client-peer-addr"`
|
||||||
|
ClientLocalAddr string `json:"client-local-addr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type json_out_server_stats struct {
|
type json_out_server_stats struct {
|
||||||
@ -465,8 +465,8 @@ func (ctl *server_ctl_server_conns_id_routes_id_peers) ServeHTTP(w http.Response
|
|||||||
Id: p.conn_id,
|
Id: p.conn_id,
|
||||||
ServerPeerAddr: p.conn.RemoteAddr().String(),
|
ServerPeerAddr: p.conn.RemoteAddr().String(),
|
||||||
ServerLocalAddr: p.conn.LocalAddr().String(),
|
ServerLocalAddr: p.conn.LocalAddr().String(),
|
||||||
ClientPeerAddr: p.cts.remote_addr,
|
ClientPeerAddr: p.client_peer_raddr,
|
||||||
ClientLocalAddr: p.cts.local_addr,
|
ClientLocalAddr: p.client_peer_laddr,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
r.pts_mtx.Unlock()
|
r.pts_mtx.Unlock()
|
||||||
@ -522,8 +522,8 @@ func (ctl *server_ctl_server_conns_id_routes_id_peers_id) ServeHTTP(w http.Respo
|
|||||||
Id: p.conn_id,
|
Id: p.conn_id,
|
||||||
ServerPeerAddr: p.conn.RemoteAddr().String(),
|
ServerPeerAddr: p.conn.RemoteAddr().String(),
|
||||||
ServerLocalAddr: p.conn.LocalAddr().String(),
|
ServerLocalAddr: p.conn.LocalAddr().String(),
|
||||||
ClientPeerAddr: p.cts.remote_addr,
|
ClientPeerAddr: p.client_peer_raddr,
|
||||||
ClientLocalAddr: p.cts.local_addr,
|
ClientLocalAddr: p.client_peer_laddr,
|
||||||
}
|
}
|
||||||
|
|
||||||
status_code = WriteJsonRespHeader(w, http.StatusOK)
|
status_code = WriteJsonRespHeader(w, http.StatusOK)
|
||||||
|
@ -12,7 +12,6 @@ import "time"
|
|||||||
type ServerPeerConn struct {
|
type ServerPeerConn struct {
|
||||||
route *ServerRoute
|
route *ServerRoute
|
||||||
conn_id PeerId
|
conn_id PeerId
|
||||||
cts *ClientConn
|
|
||||||
conn *net.TCPConn
|
conn *net.TCPConn
|
||||||
|
|
||||||
stop_chan chan bool
|
stop_chan chan bool
|
||||||
@ -22,6 +21,8 @@ type ServerPeerConn struct {
|
|||||||
client_peer_started atomic.Bool
|
client_peer_started atomic.Bool
|
||||||
client_peer_stopped atomic.Bool
|
client_peer_stopped atomic.Bool
|
||||||
client_peer_eof atomic.Bool
|
client_peer_eof atomic.Bool
|
||||||
|
client_peer_laddr string
|
||||||
|
client_peer_raddr string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServerPeerConn(r *ServerRoute, c *net.TCPConn, id PeerId) *ServerPeerConn {
|
func NewServerPeerConn(r *ServerRoute, c *net.TCPConn, id PeerId) *ServerPeerConn {
|
||||||
@ -163,6 +164,19 @@ func (spc *ServerPeerConn) ReportEvent(event_type PACKET_KIND, event_data interf
|
|||||||
|
|
||||||
switch event_type {
|
switch event_type {
|
||||||
case PACKET_KIND_PEER_STARTED:
|
case PACKET_KIND_PEER_STARTED:
|
||||||
|
var ok bool
|
||||||
|
var pd *PeerDesc
|
||||||
|
|
||||||
|
pd, ok = event_data.(*PeerDesc)
|
||||||
|
if !ok {
|
||||||
|
// something wrong. leave it unknown.
|
||||||
|
spc.client_peer_laddr = "";
|
||||||
|
spc.client_peer_raddr = "";
|
||||||
|
} else {
|
||||||
|
spc.client_peer_laddr = pd.LocalAddrStr
|
||||||
|
spc.client_peer_raddr = pd.RemoteAddrStr
|
||||||
|
}
|
||||||
|
|
||||||
if spc.client_peer_started.CompareAndSwap(false, true) {
|
if spc.client_peer_started.CompareAndSwap(false, true) {
|
||||||
spc.client_peer_status_chan <- true
|
spc.client_peer_status_chan <- true
|
||||||
}
|
}
|
||||||
|
@ -1004,6 +1004,7 @@ func (s *Server) wrap_http_handler(handler ServerHttpHandler) http.Handler {
|
|||||||
if handler.Cors(req) {
|
if handler.Cors(req) {
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
w.Header().Set("Access-Control-Allow-Headers", "*")
|
w.Header().Set("Access-Control-Allow-Headers", "*")
|
||||||
|
w.Header().Set("Access-Control-Allow-Methods", "*")
|
||||||
}
|
}
|
||||||
if req.Method == http.MethodOptions {
|
if req.Method == http.MethodOptions {
|
||||||
status_code = WriteEmptyRespHeader(w, http.StatusOK)
|
status_code = WriteEmptyRespHeader(w, http.StatusOK)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user