mirror of
				https://github.com/kaspanet/kaspad.git
				synced 2025-10-14 00:59:33 +00:00 
			
		
		
		
	 707a728656
			
		
	
	
		707a728656
		
			
		
	
	
	
	
		
			
			* [NOD-552] Add NormalizeRPCServerAddress and use it where needed * [NOD-552] Make NormalizeAddress return an error for an invalid address * [NOD-552] Use longer lines for a comment
		
			
				
	
	
		
			38 lines
		
	
	
		
			849 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			849 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package rpc
 | |
| 
 | |
| import (
 | |
| 	"github.com/kaspanet/kaspad/rpcmodel"
 | |
| 	"github.com/kaspanet/kaspad/util/network"
 | |
| )
 | |
| 
 | |
| // handleAddManualNode handles addManualNode commands.
 | |
| func handleAddManualNode(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
 | |
| 	c := cmd.(*rpcmodel.AddManualNodeCmd)
 | |
| 
 | |
| 	oneTry := c.OneTry != nil && *c.OneTry
 | |
| 
 | |
| 	addr, err := network.NormalizeAddress(c.Addr, s.cfg.DAGParams.DefaultPort)
 | |
| 	if err != nil {
 | |
| 		return nil, &rpcmodel.RPCError{
 | |
| 			Code:    rpcmodel.ErrRPCInvalidParameter,
 | |
| 			Message: err.Error(),
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	if oneTry {
 | |
| 		err = s.cfg.ConnMgr.Connect(addr, false)
 | |
| 	} else {
 | |
| 		err = s.cfg.ConnMgr.Connect(addr, true)
 | |
| 	}
 | |
| 
 | |
| 	if err != nil {
 | |
| 		return nil, &rpcmodel.RPCError{
 | |
| 			Code:    rpcmodel.ErrRPCInvalidParameter,
 | |
| 			Message: err.Error(),
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	// no data returned unless an error.
 | |
| 	return nil, nil
 | |
| }
 |