示例#1
0
//Handler for /nodemanager/start - add new Node
//mode: GET
//url: /nodemanager/start
func nodeStartHandler(nm *nodemanager.NodeManager) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		logger.Info("Starting Node")
		count := len(nm.NodesList)
		i := nm.AddNode()
		if i != count {
			wh.Error500(w)
		}

	}
}
示例#2
0
//Handler for /nodemanager/stop - stop Node
//mode: GET
//url: /nodemanager/stop?id=value
func nodeStopHandler(nm *nodemanager.NodeManager) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		logger.Info("Stoping Node")
		nodeID := r.FormValue("id")
		if nodeID == "" {
			wh.Error400(w, "Missing Node id")
			return
		}
		i, err := strconv.Atoi(nodeID)
		if err != nil {
			wh.Error400(w, "Node id must be integer")
			return
		}

		if len(nm.PubKeyList) < i {
			wh.Error400(w, "Invalid Node id")
			return
		}

		nm.NodesList[nm.PubKeyList[i]].Close()
		delete(nm.NodesList, nm.PubKeyList[i])
		nm.PubKeyList = append(nm.PubKeyList[:i], nm.PubKeyList[i+1:]...)

	}
}
示例#3
0
//Handler for /nodemanager/addtransport
//mode: POST
//url: /nodemanager/addtransport
func nodeAddTransportHandler(nm *nodemanager.NodeManager) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		logger.Info("Add transport to Node")

		var c ConfigWithID
		err := json.NewDecoder(r.Body).Decode(&c)

		if err != nil {
			wh.Error400(w, "Error decoding config for transport")
		}
		if len(nm.PubKeyList) < c.NodeID {
			wh.Error400(w, "Invalid Node id")
			return
		}

		node := nm.GetNodeByIndex(c.NodeID)
		nodemanager.AddPeersToNode(node, c.Config)
	}
}
示例#4
0
//Handler for /nodemanager/removetransport
//mode: POST
//url: /nodemanager/removetransport
func nodeRemoveTransportHandler(nm *nodemanager.NodeManager) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		logger.Info("Remove transport from Node")

		var c TransportWithID
		err := json.NewDecoder(r.Body).Decode(&c)

		if err != nil {
			wh.Error400(w, "Error decoding config for transport")
		}
		if len(nm.PubKeyList) < c.NodeID {
			wh.Error400(w, "Invalid Node id")
			return
		}
		logger.Info(strconv.Itoa(c.NodeID))

		nm.RemoveTransportsFromNode(c.NodeID, c.Transport)

	}
}
示例#5
0
//Handler for /nodemanager/gettransports
//mode: GET
//url: /nodemanager/gettransports?id=value
func nodeGetTransportsHandler(nm *nodemanager.NodeManager) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		logger.Info("Get transport from Node")
		nodeID := r.FormValue("id")
		if nodeID == "" {
			wh.Error400(w, "Missing Node id")
			return
		}
		i, err := strconv.Atoi(nodeID)
		if err != nil {
			wh.Error400(w, "Node id must be integer")
			return
		}

		if len(nm.PubKeyList) < i {
			wh.Error400(w, "Invalid Node id")
			return
		}

		wh.SendJSON(w, nm.GetTransportsFromNode(i))

	}
}