add update check for validate relay

This commit is contained in:
abhishek9686 2024-03-04 13:39:33 +07:00
parent d69d0ed2e2
commit 8ac864fec8
3 changed files with 5 additions and 5 deletions

View file

@ -650,7 +650,7 @@ func updateNode(w http.ResponseWriter, r *http.Request) {
NodeID: newNode.ID.String(), NodeID: newNode.ID.String(),
NetID: newNode.Network, NetID: newNode.Network,
RelayedNodes: newNode.RelayedNodes, RelayedNodes: newNode.RelayedNodes,
}) }, true)
if err != nil { if err != nil {
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest")) logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
return return

View file

@ -29,6 +29,6 @@ var RelayUpdates = func(currentNode, newNode *models.Node) bool {
return false return false
} }
var ValidateRelay = func(relay models.RelayRequest) error { var ValidateRelay = func(relay models.RelayRequest, update bool) error {
return nil return nil
} }

View file

@ -44,7 +44,7 @@ func CreateRelay(relay models.RelayRequest) ([]models.Node, models.Node, error)
if host.OS != "linux" { if host.OS != "linux" {
return returnnodes, models.Node{}, fmt.Errorf("only linux machines can be relay nodes") return returnnodes, models.Node{}, fmt.Errorf("only linux machines can be relay nodes")
} }
err = ValidateRelay(relay) err = ValidateRelay(relay, false)
if err != nil { if err != nil {
return returnnodes, models.Node{}, err return returnnodes, models.Node{}, err
} }
@ -101,14 +101,14 @@ func SetRelayedNodes(setRelayed bool, relay string, relayed []string) []models.N
// } // }
// ValidateRelay - checks if relay is valid // ValidateRelay - checks if relay is valid
func ValidateRelay(relay models.RelayRequest) error { func ValidateRelay(relay models.RelayRequest, update bool) error {
var err error var err error
node, err := logic.GetNodeByID(relay.NodeID) node, err := logic.GetNodeByID(relay.NodeID)
if err != nil { if err != nil {
return err return err
} }
if node.IsRelay { if !update && node.IsRelay {
return errors.New("node is already acting as a relay") return errors.New("node is already acting as a relay")
} }
for _, relayedNodeID := range relay.RelayedNodes { for _, relayedNodeID := range relay.RelayedNodes {