Skip to content

Commit 872ad58

Browse files
fix(broadcast): corrected client server addr
1 parent a997e33 commit 872ad58

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

clientserver.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ type csr struct {
4545
}
4646

4747
type ClientServer struct {
48-
id uint64 // should correpond to the ID given to the manager
48+
id uint64 // should correpond to the MachineID given to the manager
49+
addr string
4950
mu sync.Mutex
5051
csr map[uint64]*csr
5152
reqChan chan *ClientRequest
@@ -78,7 +79,7 @@ func (srv *ClientServer) AddRequest(broadcastID uint64, clientCtx context.Contex
7879

7980
BroadcastID: broadcastID,
8081
IsBroadcastClient: true,
81-
OriginAddr: srv.lis.Addr().String(),
82+
OriginAddr: srv.addr,
8283
}
8384
// we expect one response when we are done
8485
doneChan := make(chan protoreflect.ProtoMessage, 1)
@@ -215,7 +216,7 @@ func (s *ClientServer) NodeStream(srv ordering.Gorums_NodeStreamServer) error {
215216
}
216217
}
217218

218-
// NewServer returns a new instance of GorumsServer.
219+
// NewClientServer returns a new instance of ClientServer.
219220
// This function is intended for internal Gorums use.
220221
// You should call `NewServer` in the generated code instead.
221222
func NewClientServer(lis net.Listener, opts ...ServerOption) *ClientServer {
@@ -230,6 +231,7 @@ func NewClientServer(lis net.Listener, opts ...ServerOption) *ClientServer {
230231
ctx, cancel := context.WithCancel(context.Background())
231232
srv := &ClientServer{
232233
id: serverOpts.machineID,
234+
addr: serverOpts.listenAddr,
233235
ctx: ctx,
234236
cancelCtx: cancel,
235237
csr: make(map[uint64]*csr),
@@ -251,6 +253,9 @@ func (srv *ClientServer) RegisterHandler(method string, handler requestHandler)
251253

252254
// Serve starts serving on the listener.
253255
func (srv *ClientServer) Serve(listener net.Listener) error {
256+
if srv.addr == "" {
257+
srv.addr = listener.Addr().String()
258+
}
254259
return srv.grpcServer.Serve(listener)
255260
}
256261

@@ -262,9 +267,6 @@ func createClient(addr string, dialOpts []grpc.DialOption) (*broadcast.Client, e
262267
opts.grpcDialOpts = dialOpts
263268
mgr := &RawManager{
264269
opts: opts,
265-
/*opts: managerOptions{
266-
grpcDialOpts: dialOpts,
267-
},*/
268270
}
269271
node, err := NewRawNode(addr)
270272
if err != nil {

0 commit comments

Comments
 (0)