permitted the client mode to start without server addresses

This commit is contained in:
hyung-hwan 2024-12-09 15:43:29 +09:00
parent db48395b13
commit f1c146d94f
2 changed files with 23 additions and 20 deletions

View File

@ -1075,6 +1075,10 @@ func (c *Client) AddNewClientConn(cfg *ClientConfig) (*ClientConn, error) {
var ok bool
var id uint32
if len(cfg.ServerAddrs) <= 0 {
return nil, fmt.Errorf("no server rpc address specified")
}
cts = NewClientConn(c, cfg)
c.cts_mtx.Lock()
@ -1295,17 +1299,9 @@ func (c *Client) RunTask(wg *sync.WaitGroup) {
// so no call to wg.Done()
}
func (c *Client) start_service(data interface{}) (*ClientConn, error) {
func (c *Client) start_service(cfg *ClientConfig) (*ClientConn, error) {
var cts *ClientConn
var err error
var cfg *ClientConfig
var ok bool
cfg, ok = data.(*ClientConfig)
if !ok {
err = fmt.Errorf("invalid configuration given")
return nil, err
}
cts, err = c.AddNewClientConn(cfg)
if err != nil {
@ -1320,14 +1316,24 @@ func (c *Client) start_service(data interface{}) (*ClientConn, error) {
}
func (c *Client) StartService(data interface{}) {
var cts *ClientConn
var err error
var cfg *ClientConfig
var ok bool
cts, err = c.start_service(data)
if err != nil {
c.log.Write("", LOG_ERROR, "Failed to start service - %s", err.Error())
cfg, ok = data.(*ClientConfig)
if !ok {
c.log.Write("", LOG_ERROR, "Failed to start service - invalid configuration - %v", data)
} else {
c.log.Write("", LOG_INFO, "Started service for %v [%d]", cts.cfg.ServerAddrs, cts.cfg.Id)
var cts *ClientConn
var err error
if len(cfg.ServerAddrs) > 0 {
cts, err = c.start_service(cfg)
if err != nil {
c.log.Write("", LOG_ERROR, "Failed to start service - %s", err.Error())
} else {
c.log.Write("", LOG_INFO, "Started service for %v [%d]", cts.cfg.ServerAddrs, cts.cfg.Id)
}
}
}
}

View File

@ -234,14 +234,11 @@ func client_main(ctl_addrs []string, rpc_addrs []string, peer_addrs []string, cf
log_mask = log_strings_to_mask(cfg.APP.LogMask)
}
if len(rpc_addrs) <= 0 {
return fmt.Errorf("no rpc server address specified")
}
// unlke the server, we allow the client to start with no rpc address.
// no check if len(rpc_addrs) <= 0 is mdde here.
cc.ServerAddrs = rpc_addrs
cc.PeerAddrs = peer_addrs
// TODO: Change out field depending on cfg.APP.LogFile
logger = &AppLogger{id: "client", out: os.Stderr, mask: log_mask}
c = hodu.NewClient(
context.Background(),