@@ -26,8 +26,8 @@ type Server struct {
2626 * protocol.Protocol
2727 config * Config
2828 callbackContext CallbackContext
29+ protoOptions protocol.ProtocolOptions
2930 ackCount int
30- stateDone bool
3131 requestTxIdsResultChan chan []TxIdAndSize
3232 requestTxsResultChan chan []TxBody
3333 onceStart sync.Once
@@ -36,28 +36,34 @@ type Server struct {
3636// NewServer returns a new TxSubmission server object
3737func NewServer (protoOptions protocol.ProtocolOptions , cfg * Config ) * Server {
3838 s := & Server {
39- config : cfg ,
39+ config : cfg ,
40+ // Save this for re-use later
41+ protoOptions : protoOptions ,
4042 requestTxIdsResultChan : make (chan []TxIdAndSize ),
4143 requestTxsResultChan : make (chan []TxBody ),
4244 }
4345 s .callbackContext = CallbackContext {
4446 Server : s ,
4547 ConnectionId : protoOptions .ConnectionId ,
4648 }
49+ s .initProtocol ()
50+ return s
51+ }
52+
53+ func (s * Server ) initProtocol () {
4754 protoConfig := protocol.ProtocolConfig {
4855 Name : ProtocolName ,
4956 ProtocolId : ProtocolId ,
50- Muxer : protoOptions .Muxer ,
51- ErrorChan : protoOptions .ErrorChan ,
52- Mode : protoOptions .Mode ,
57+ Muxer : s . protoOptions .Muxer ,
58+ ErrorChan : s . protoOptions .ErrorChan ,
59+ Mode : s . protoOptions .Mode ,
5360 Role : protocol .ProtocolRoleServer ,
5461 MessageHandlerFunc : s .messageHandler ,
5562 MessageFromCborFunc : NewMsgFromCbor ,
5663 StateMap : StateMap ,
5764 InitialState : stateInit ,
5865 }
5966 s .Protocol = protocol .New (protoConfig )
60- return s
6167}
6268
6369func (s * Server ) Start () {
@@ -98,9 +104,6 @@ func (s *Server) RequestTxIds(
98104 blocking bool ,
99105 reqCount int ,
100106) ([]TxIdAndSize , error ) {
101- if s .stateDone {
102- return nil , protocol .ProtocolShuttingDownError
103- }
104107 msg := NewMsgRequestTxIds (blocking , uint16 (s .ackCount ), uint16 (reqCount ))
105108 if err := s .SendMessage (msg ); err != nil {
106109 return nil , err
@@ -117,9 +120,6 @@ func (s *Server) RequestTxIds(
117120
118121// RequestTxs requests the content of the requested TX identifiers from the remote node's mempool
119122func (s * Server ) RequestTxs (txIds []TxId ) ([]TxBody , error ) {
120- if s .stateDone {
121- return nil , protocol .ProtocolShuttingDownError
122- }
123123 msg := NewMsgRequestTxs (txIds )
124124 if err := s .SendMessage (msg ); err != nil {
125125 return nil , err
@@ -147,7 +147,12 @@ func (s *Server) handleReplyTxs(msg protocol.Message) error {
147147}
148148
149149func (s * Server ) handleDone () error {
150- s .stateDone = true
150+ // Restart protocol
151+ s .Protocol .Stop ()
152+ s .initProtocol ()
153+ s .requestTxIdsResultChan = make (chan []TxIdAndSize )
154+ s .requestTxsResultChan = make (chan []TxBody )
155+ s .Protocol .Start ()
151156 return nil
152157}
153158
0 commit comments