implemented client peer deletion
This commit is contained in:
parent
4d927b9a7f
commit
18b3028a46
@ -386,7 +386,6 @@ func (ctl *client_ctl_client_conns_id_routes_id) ServeHTTP(w http.ResponseWriter
|
|||||||
switch req.Method {
|
switch req.Method {
|
||||||
case http.MethodGet:
|
case http.MethodGet:
|
||||||
var r *ClientRoute
|
var r *ClientRoute
|
||||||
|
|
||||||
r = cts.FindClientRouteById(uint32(route_nid))
|
r = cts.FindClientRouteById(uint32(route_nid))
|
||||||
if r == nil {
|
if r == nil {
|
||||||
status_code = http.StatusNotFound; w.WriteHeader(status_code)
|
status_code = http.StatusNotFound; w.WriteHeader(status_code)
|
||||||
@ -401,13 +400,8 @@ func (ctl *client_ctl_client_conns_id_routes_id) ServeHTTP(w http.ResponseWriter
|
|||||||
if err != nil { goto oops }
|
if err != nil { goto oops }
|
||||||
|
|
||||||
case http.MethodDelete:
|
case http.MethodDelete:
|
||||||
err = cts.RemoveClientRouteById(uint32(route_nid))
|
cts.ReqStop()
|
||||||
if err != nil {
|
|
||||||
status_code = http.StatusNotFound; w.WriteHeader(status_code)
|
|
||||||
if err = je.Encode(json_errmsg{Text: err.Error()}); err != nil { goto oops }
|
|
||||||
} else {
|
|
||||||
status_code = http.StatusNoContent; w.WriteHeader(status_code)
|
status_code = http.StatusNoContent; w.WriteHeader(status_code)
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
status_code = http.StatusBadRequest; w.WriteHeader(status_code)
|
status_code = http.StatusBadRequest; w.WriteHeader(status_code)
|
||||||
@ -483,7 +477,9 @@ func (ctl *client_ctl_client_conns_id_routes_id_peers) ServeHTTP(w http.Response
|
|||||||
status_code = http.StatusOK; w.WriteHeader(status_code)
|
status_code = http.StatusOK; w.WriteHeader(status_code)
|
||||||
if err = je.Encode(jcp); err != nil { goto oops }
|
if err = je.Encode(jcp); err != nil { goto oops }
|
||||||
|
|
||||||
// TODO: implemente MethodDelete to support forced disconnect from the peer.
|
case http.MethodDelete:
|
||||||
|
r.ReqStopAllClientPeerConns()
|
||||||
|
status_code = http.StatusNoContent; w.WriteHeader(status_code)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
status_code = http.StatusBadRequest; w.WriteHeader(status_code)
|
status_code = http.StatusBadRequest; w.WriteHeader(status_code)
|
||||||
@ -560,6 +556,10 @@ func (ctl *client_ctl_client_conns_id_routes_id_peers_id) ServeHTTP(w http.Respo
|
|||||||
status_code = http.StatusOK; w.WriteHeader(status_code)
|
status_code = http.StatusOK; w.WriteHeader(status_code)
|
||||||
if err = je.Encode(jcp); err != nil { goto oops }
|
if err = je.Encode(jcp); err != nil { goto oops }
|
||||||
|
|
||||||
|
case http.MethodDelete:
|
||||||
|
p.ReqStop()
|
||||||
|
status_code = http.StatusNoContent; w.WriteHeader(status_code)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
status_code = http.StatusBadRequest; w.WriteHeader(status_code)
|
status_code = http.StatusBadRequest; w.WriteHeader(status_code)
|
||||||
}
|
}
|
||||||
|
23
client.go
23
client.go
@ -180,6 +180,29 @@ func (r *ClientRoute) RemoveClientPeerConn(ptc *ClientPeerConn) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *ClientRoute) RemoveAllClientPeerConns() {
|
||||||
|
var c *ClientPeerConn
|
||||||
|
|
||||||
|
r.ptc_mtx.Lock()
|
||||||
|
defer r.ptc_mtx.Unlock()
|
||||||
|
|
||||||
|
for _, c = range r.ptc_map {
|
||||||
|
delete(r.ptc_map, c.conn_id)
|
||||||
|
c.ReqStop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ClientRoute) ReqStopAllClientPeerConns() {
|
||||||
|
var c *ClientPeerConn
|
||||||
|
|
||||||
|
r.ptc_mtx.Lock()
|
||||||
|
defer r.ptc_mtx.Unlock()
|
||||||
|
|
||||||
|
for _, c = range r.ptc_map {
|
||||||
|
c.ReqStop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (r *ClientRoute) FindClientPeerConnById(conn_id uint32) *ClientPeerConn {
|
func (r *ClientRoute) FindClientPeerConnById(conn_id uint32) *ClientPeerConn {
|
||||||
var c *ClientPeerConn
|
var c *ClientPeerConn
|
||||||
var ok bool
|
var ok bool
|
||||||
|
Loading…
x
Reference in New Issue
Block a user