permitted the client mode to start without server addresses
This commit is contained in:
parent
db48395b13
commit
f1c146d94f
36
client.go
36
client.go
@ -1075,6 +1075,10 @@ func (c *Client) AddNewClientConn(cfg *ClientConfig) (*ClientConn, error) {
|
|||||||
var ok bool
|
var ok bool
|
||||||
var id uint32
|
var id uint32
|
||||||
|
|
||||||
|
if len(cfg.ServerAddrs) <= 0 {
|
||||||
|
return nil, fmt.Errorf("no server rpc address specified")
|
||||||
|
}
|
||||||
|
|
||||||
cts = NewClientConn(c, cfg)
|
cts = NewClientConn(c, cfg)
|
||||||
|
|
||||||
c.cts_mtx.Lock()
|
c.cts_mtx.Lock()
|
||||||
@ -1295,17 +1299,9 @@ func (c *Client) RunTask(wg *sync.WaitGroup) {
|
|||||||
// so no call to wg.Done()
|
// 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 cts *ClientConn
|
||||||
var err error
|
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)
|
cts, err = c.AddNewClientConn(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1320,14 +1316,24 @@ func (c *Client) start_service(data interface{}) (*ClientConn, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) StartService(data interface{}) {
|
func (c *Client) StartService(data interface{}) {
|
||||||
var cts *ClientConn
|
var cfg *ClientConfig
|
||||||
var err error
|
var ok bool
|
||||||
|
|
||||||
cts, err = c.start_service(data)
|
cfg, ok = data.(*ClientConfig)
|
||||||
if err != nil {
|
if !ok {
|
||||||
c.log.Write("", LOG_ERROR, "Failed to start service - %s", err.Error())
|
c.log.Write("", LOG_ERROR, "Failed to start service - invalid configuration - %v", data)
|
||||||
} else {
|
} 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
log_mask = log_strings_to_mask(cfg.APP.LogMask)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(rpc_addrs) <= 0 {
|
// unlke the server, we allow the client to start with no rpc address.
|
||||||
return fmt.Errorf("no rpc server address specified")
|
// no check if len(rpc_addrs) <= 0 is mdde here.
|
||||||
}
|
|
||||||
|
|
||||||
cc.ServerAddrs = rpc_addrs
|
cc.ServerAddrs = rpc_addrs
|
||||||
cc.PeerAddrs = peer_addrs
|
cc.PeerAddrs = peer_addrs
|
||||||
|
|
||||||
// TODO: Change out field depending on cfg.APP.LogFile
|
|
||||||
logger = &AppLogger{id: "client", out: os.Stderr, mask: log_mask}
|
logger = &AppLogger{id: "client", out: os.Stderr, mask: log_mask}
|
||||||
c = hodu.NewClient(
|
c = hodu.NewClient(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user