changed to store the target server address string as given by the caller and not resolve the string
This commit is contained in:
@ -4,7 +4,6 @@ import "encoding/json"
|
||||
import "net/http"
|
||||
import "strconv"
|
||||
|
||||
|
||||
/*
|
||||
* POST GET PUT DELETE
|
||||
* /servers - create new server list all servers bulk update delete all servers
|
||||
@ -24,8 +23,16 @@ type json_errmsg struct {
|
||||
Text string `json:"error-text"`
|
||||
}
|
||||
|
||||
type json_in_peer_addrs struct {
|
||||
PeerAddrs []string `json:"peer-addrs"`
|
||||
type json_in_client_conn struct {
|
||||
ServerAddr string `json:"server-addr"`
|
||||
}
|
||||
|
||||
type json_in_client_route struct {
|
||||
ClientPeerAddr string `json:"client-peer-addr"`
|
||||
}
|
||||
|
||||
type json_out_client_conn_id struct {
|
||||
Id uint32 `json:"id"`
|
||||
}
|
||||
|
||||
type json_out_client_conn struct {
|
||||
@ -34,6 +41,10 @@ type json_out_client_conn struct {
|
||||
Routes []json_out_client_route `json:"routes"`
|
||||
}
|
||||
|
||||
type json_out_client_route_id struct {
|
||||
Id uint32 `json:"id"`
|
||||
}
|
||||
|
||||
type json_out_client_route struct {
|
||||
Id uint32 `json:"id"`
|
||||
ClientPeerAddr string `json:"client-peer-addr"`
|
||||
@ -94,11 +105,11 @@ func (ctl *client_ctl_client_conns) ServeHTTP(w http.ResponseWriter, req *http.R
|
||||
for _, r = range cts.route_map {
|
||||
jsp = append(jsp, json_out_client_route{
|
||||
Id: r.id,
|
||||
ClientPeerAddr: r.peer_addr.String(),
|
||||
ClientPeerAddr: r.peer_addr,
|
||||
ServerPeerListenAddr: r.server_peer_listen_addr.String(),
|
||||
})
|
||||
}
|
||||
js = append(js, json_out_client_conn{Id: cts.id, ServerAddr: cts.saddr.String(), Routes: jsp})
|
||||
js = append(js, json_out_client_conn{Id: cts.id, ServerAddr: cts.cfg.ServerAddr, Routes: jsp})
|
||||
cts.route_mtx.Unlock()
|
||||
}
|
||||
c.cts_mtx.Unlock()
|
||||
@ -108,7 +119,7 @@ func (ctl *client_ctl_client_conns) ServeHTTP(w http.ResponseWriter, req *http.R
|
||||
|
||||
case http.MethodPost:
|
||||
// add a new server connection
|
||||
var s ClientCtlParamServer
|
||||
var s json_in_client_conn
|
||||
var cc ClientConfig
|
||||
var cts *ClientConn
|
||||
|
||||
@ -118,14 +129,14 @@ func (ctl *client_ctl_client_conns) ServeHTTP(w http.ResponseWriter, req *http.R
|
||||
goto done
|
||||
}
|
||||
cc.ServerAddr = s.ServerAddr
|
||||
cc.PeerAddrs = s.PeerAddrs
|
||||
//cc.PeerAddrs = s.PeerAddrs
|
||||
cts, err = c.start_service(&cc) // TODO: this can be blocking. do we have to resolve addresses before calling this? also not good because resolution succeed or fail at each attempt. however ok as ServeHTTP itself is in a goroutine?
|
||||
if err != nil {
|
||||
status_code = http.StatusInternalServerError; w.WriteHeader(status_code)
|
||||
if err = je.Encode(json_errmsg{Text: err.Error()}); err != nil { goto oops }
|
||||
} else {
|
||||
status_code = http.StatusCreated; w.WriteHeader(status_code)
|
||||
if err = je.Encode(cts.cfg); err != nil { goto oops }
|
||||
if err = je.Encode(json_out_client_conn_id{Id: cts.id}); err != nil { goto oops }
|
||||
}
|
||||
|
||||
case http.MethodDelete:
|
||||
@ -194,18 +205,18 @@ func (ctl *client_ctl_client_conns_id) ServeHTTP(w http.ResponseWriter, req *htt
|
||||
for _, r = range cts.route_map {
|
||||
jsp = append(jsp, json_out_client_route{
|
||||
Id: r.id,
|
||||
ClientPeerAddr: r.peer_addr.String(),
|
||||
ClientPeerAddr: r.peer_addr,
|
||||
ServerPeerListenAddr: r.server_peer_listen_addr.String(),
|
||||
})
|
||||
}
|
||||
js = &json_out_client_conn{Id: cts.id, ServerAddr: cts.saddr.String(), Routes: jsp}
|
||||
js = &json_out_client_conn{Id: cts.id, ServerAddr: cts.cfg.ServerAddr, Routes: jsp}
|
||||
cts.route_mtx.Unlock()
|
||||
|
||||
status_code = http.StatusOK; w.WriteHeader(status_code)
|
||||
if err = je.Encode(js); err != nil { goto oops }
|
||||
|
||||
case http.MethodDelete:
|
||||
/*
|
||||
/* TODO
|
||||
err = c.RemoveClientConnById(uint32(conn_nid))
|
||||
if err != nil {
|
||||
status_code = http.StatusNotFound; w.WriteHeader(status_code)
|
||||
@ -264,13 +275,12 @@ func (ctl *client_ctl_client_conns_id_routes) ServeHTTP(w http.ResponseWriter, r
|
||||
var r *ClientRoute
|
||||
var jsp []json_out_client_route
|
||||
|
||||
|
||||
jsp = make([]json_out_client_route, 0)
|
||||
cts.route_mtx.Lock()
|
||||
for _, r = range cts.route_map {
|
||||
jsp = append(jsp, json_out_client_route{
|
||||
Id: r.id,
|
||||
ClientPeerAddr: r.peer_addr.String(),
|
||||
ClientPeerAddr: r.peer_addr,
|
||||
ServerPeerListenAddr: r.server_peer_listen_addr.String(),
|
||||
})
|
||||
}
|
||||
@ -280,29 +290,28 @@ func (ctl *client_ctl_client_conns_id_routes) ServeHTTP(w http.ResponseWriter, r
|
||||
if err = je.Encode(jsp); err != nil { goto oops }
|
||||
|
||||
case http.MethodPost:
|
||||
var pa json_in_peer_addrs
|
||||
var cts *ClientConn
|
||||
var jcr json_in_client_route
|
||||
var r *ClientRoute
|
||||
|
||||
err = json.NewDecoder(req.Body).Decode(&pa)
|
||||
err = json.NewDecoder(req.Body).Decode(&jcr)
|
||||
if err != nil {
|
||||
status_code = http.StatusBadRequest; w.WriteHeader(status_code)
|
||||
goto done
|
||||
}
|
||||
|
||||
cts = c.FindClientConnById(uint32(conn_nid))
|
||||
if cts == nil {
|
||||
status_code = http.StatusNotFound; w.WriteHeader(status_code)
|
||||
if err = je.Encode(json_errmsg{Text: "wrong connection id - " + conn_id}); err != nil { goto oops }
|
||||
r, err = cts.AddNewClientRoute(jcr.ClientPeerAddr, ROUTE_PROTO_TCP) // TODO: configurable protocol
|
||||
if err != nil {
|
||||
status_code = http.StatusInternalServerError; w.WriteHeader(status_code)
|
||||
if err = je.Encode(json_errmsg{Text: err.Error()}); err != nil { goto oops }
|
||||
} else {
|
||||
err = cts.AddClientRoutes(pa.PeerAddrs)
|
||||
if err != nil {
|
||||
status_code = http.StatusInternalServerError; w.WriteHeader(status_code)
|
||||
if err = je.Encode(json_errmsg{Text: err.Error()}); err != nil { goto oops }
|
||||
} else {
|
||||
status_code = http.StatusCreated; w.WriteHeader(status_code)
|
||||
}
|
||||
status_code = http.StatusCreated; w.WriteHeader(status_code)
|
||||
if err = je.Encode(json_out_client_route_id{Id: r.id}); err != nil { goto oops }
|
||||
}
|
||||
|
||||
case http.MethodDelete:
|
||||
cts.RemoveClientRoutes()
|
||||
status_code = http.StatusNoContent; w.WriteHeader(status_code)
|
||||
|
||||
default:
|
||||
status_code = http.StatusBadRequest; w.WriteHeader(status_code)
|
||||
}
|
||||
@ -369,7 +378,7 @@ func (ctl *client_ctl_client_conns_id_routes_id) ServeHTTP(w http.ResponseWriter
|
||||
}
|
||||
err = je.Encode(json_out_client_route{
|
||||
Id: r.id,
|
||||
ClientPeerAddr: r.peer_addr.String(),
|
||||
ClientPeerAddr: r.peer_addr,
|
||||
ServerPeerListenAddr: r.server_peer_listen_addr.String(),
|
||||
})
|
||||
if err != nil { goto oops }
|
||||
|
Reference in New Issue
Block a user