watchtower/wtwire/create_session_reply: return last applied
This commit is contained in:
parent
9aa775e64e
commit
9b1bc9fd79
@ -29,14 +29,14 @@ func (s *Server) handleCreateSession(peer Peer, id *wtdb.SessionID,
|
||||
log.Debugf("Already have session for %s", id)
|
||||
return s.replyCreateSession(
|
||||
peer, id, wtwire.CreateSessionCodeAlreadyExists,
|
||||
existingInfo.RewardAddress,
|
||||
existingInfo.LastApplied, existingInfo.RewardAddress,
|
||||
)
|
||||
|
||||
// Some other database error occurred, return a temporary failure.
|
||||
case err != wtdb.ErrSessionNotFound:
|
||||
log.Errorf("unable to load session info for %s", id)
|
||||
return s.replyCreateSession(
|
||||
peer, id, wtwire.CodeTemporaryFailure, nil,
|
||||
peer, id, wtwire.CodeTemporaryFailure, 0, nil,
|
||||
)
|
||||
}
|
||||
|
||||
@ -45,7 +45,8 @@ func (s *Server) handleCreateSession(peer Peer, id *wtdb.SessionID,
|
||||
log.Debugf("Rejecting CreateSession from %s, unsupported blob "+
|
||||
"type %s", id, req.BlobType)
|
||||
return s.replyCreateSession(
|
||||
peer, id, wtwire.CreateSessionCodeRejectBlobType, nil,
|
||||
peer, id, wtwire.CreateSessionCodeRejectBlobType, 0,
|
||||
nil,
|
||||
)
|
||||
}
|
||||
|
||||
@ -61,7 +62,7 @@ func (s *Server) handleCreateSession(peer Peer, id *wtdb.SessionID,
|
||||
log.Errorf("Unable to generate reward addr for %s: %v",
|
||||
id, err)
|
||||
return s.replyCreateSession(
|
||||
peer, id, wtwire.CodeTemporaryFailure, nil,
|
||||
peer, id, wtwire.CodeTemporaryFailure, 0, nil,
|
||||
)
|
||||
}
|
||||
|
||||
@ -72,7 +73,7 @@ func (s *Server) handleCreateSession(peer Peer, id *wtdb.SessionID,
|
||||
log.Errorf("Unable to generate reward script for "+
|
||||
"%s: %v", id, err)
|
||||
return s.replyCreateSession(
|
||||
peer, id, wtwire.CodeTemporaryFailure, nil,
|
||||
peer, id, wtwire.CodeTemporaryFailure, 0, nil,
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -99,14 +100,14 @@ func (s *Server) handleCreateSession(peer Peer, id *wtdb.SessionID,
|
||||
if err != nil {
|
||||
log.Errorf("unable to create session for %s", id)
|
||||
return s.replyCreateSession(
|
||||
peer, id, wtwire.CodeTemporaryFailure, nil,
|
||||
peer, id, wtwire.CodeTemporaryFailure, 0, nil,
|
||||
)
|
||||
}
|
||||
|
||||
log.Infof("Accepted session for %s", id)
|
||||
|
||||
return s.replyCreateSession(
|
||||
peer, id, wtwire.CodeOK, rewardScript,
|
||||
peer, id, wtwire.CodeOK, 0, rewardScript,
|
||||
)
|
||||
}
|
||||
|
||||
@ -115,10 +116,11 @@ func (s *Server) handleCreateSession(peer Peer, id *wtdb.SessionID,
|
||||
// Otherwise, this method returns a connection error to ensure we don't continue
|
||||
// communication with the client.
|
||||
func (s *Server) replyCreateSession(peer Peer, id *wtdb.SessionID,
|
||||
code wtwire.ErrorCode, data []byte) error {
|
||||
code wtwire.ErrorCode, lastApplied uint16, data []byte) error {
|
||||
|
||||
msg := &wtwire.CreateSessionReply{
|
||||
Code: code,
|
||||
LastApplied: lastApplied,
|
||||
Data: data,
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,12 @@ type CreateSessionReply struct {
|
||||
// Code will be non-zero if the watchtower rejected the session init.
|
||||
Code CreateSessionCode
|
||||
|
||||
// LastApplied is the tower's last accepted sequence number for the
|
||||
// session. This is useful when the session already exists but the
|
||||
// client doesn't realize it's already used the session, such as after a
|
||||
// restoration.
|
||||
LastApplied uint16
|
||||
|
||||
// Data is a byte slice returned the caller of the message, and is to be
|
||||
// interpreted according to the error Code. When the response is
|
||||
// CreateSessionCodeOK, data encodes the reward address to be included in
|
||||
@ -63,6 +69,7 @@ var _ Message = (*CreateSessionReply)(nil)
|
||||
func (m *CreateSessionReply) Decode(r io.Reader, pver uint32) error {
|
||||
return ReadElements(r,
|
||||
&m.Code,
|
||||
&m.LastApplied,
|
||||
&m.Data,
|
||||
)
|
||||
}
|
||||
@ -74,6 +81,7 @@ func (m *CreateSessionReply) Decode(r io.Reader, pver uint32) error {
|
||||
func (m *CreateSessionReply) Encode(w io.Writer, pver uint32) error {
|
||||
return WriteElements(w,
|
||||
m.Code,
|
||||
m.LastApplied,
|
||||
m.Data,
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user