Fixup Token Requests
continuous-integration/drone/pr Build was killed Details
continuous-integration/drone/push Build was killed Details

This commit is contained in:
Sarah Jamie Lewis 2021-09-09 12:05:14 -07:00
parent a28896c293
commit 271ecdb8ec
4 changed files with 27 additions and 23 deletions

View File

@ -159,7 +159,6 @@ type ModifyServers interface {
// SendMessages enables a caller to sender messages to a contact
type SendMessages interface {
SendMessage(handle string, message string) error
SendGetValToPeer(string, string, string)

View File

@ -450,7 +450,7 @@ func (e *engine) sendGetValToPeer(eventID, onion, scope, path string) error {
return err
}
e.getValRequests.Store(onion + eventID, message)
e.getValRequests.Store(onion+eventID, message)
return e.sendPeerMessage(onion, model3.PeerMessage{ID: eventID, Context: event.ContextGetVal, Data: message})
}
@ -519,16 +519,16 @@ func (e *engine) sendMessageToGroup(groupID string, server string, ct []byte, si
func (e *engine) handlePeerMessage(hostname string, eventID string, context string, message []byte) {
log.Debugf("New message from peer: %v %v", hostname, context)
if context == event.ContextAck {
if context == event.ContextAck {
e.peerAck(hostname, eventID)
} else if context == event.ContextRetVal {
req, ok := e.getValRequests.Load(hostname + eventID)
req, ok := e.getValRequests.Load(hostname + eventID)
if ok {
reqStr := req.([]byte)
e.handlePeerRetVal(hostname, reqStr, message)
e.getValRequests.Delete(hostname + eventID)
e.getValRequests.Delete(hostname + eventID)
} else {
log.Errorf("could not find val request for %v %s",hostname, eventID)
log.Errorf("could not find val request for %v %s", hostname, eventID)
}
} else if context == event.ContextGetVal {
var getVal peerGetVal

View File

@ -79,9 +79,9 @@ func (pa *PeerApp) listen() {
var peerMessage model2.PeerMessage
err := json.Unmarshal(message, &peerMessage)
if err == nil {
if pa.IsAllowed(pa.connection.Hostname()) {
pa.MessageHandler(pa.connection.Hostname(), peerMessage.ID, peerMessage.Context, peerMessage.Data)
}
if pa.IsAllowed(pa.connection.Hostname()) {
pa.MessageHandler(pa.connection.Hostname(), peerMessage.ID, peerMessage.Context, peerMessage.Data)
}
} else {
log.Errorf("Error unmarshalling PeerMessage package: %x %v", message, err)
}

View File

@ -72,7 +72,6 @@ func (ta *TokenBoardClient) Init(connection tapir.Connection) {
go ta.Listen()
// Optimistically acquire many tokens for this server...
go ta.MakePayment()
go ta.MakePayment()
ta.Replay()
} else {
connection.Close()
@ -179,20 +178,26 @@ func (ta *TokenBoardClient) MakePayment() error {
powTokenApp := new(applications.ApplicationChain).
ChainApplication(new(applications.ProofOfWorkApplication), applications.SuccessfulProofOfWorkCapability).
ChainApplication(tokenApplication, applications.HasTokensCapability)
client.Connect(ta.tokenServiceOnion, powTokenApp)
log.Debugf("Waiting for successful PoW Auth...")
conn, err := client.WaitForCapabilityOrClose(ta.tokenServiceOnion, applications.HasTokensCapability)
if err == nil {
powtapp, _ := conn.App().(*applications.TokenApplication)
// Update tokens...we need a lock here to prevent SpendToken from modifying the tokens
// during this process..
log.Debugf("Updating Tokens")
ta.tokenLock.Lock()
ta.tokens = append(ta.tokens, powtapp.Tokens...)
ta.tokenLock.Unlock()
log.Debugf("Transcript: %v", powtapp.Transcript().OutputTranscriptToAudit())
conn.Close()
return nil
connected, err := client.Connect(ta.tokenServiceOnion, powTokenApp)
if connected == true && err == nil {
conn, err := client.WaitForCapabilityOrClose(ta.tokenServiceOnion, applications.HasTokensCapability)
if err == nil {
powtapp, ok := conn.App().(*applications.TokenApplication)
if ok {
// Update tokens...we need a lock here to prevent SpendToken from modifying the tokens
// during this process..
log.Debugf("Updating Tokens")
ta.tokenLock.Lock()
ta.tokens = append(ta.tokens, powtapp.Tokens...)
ta.tokenLock.Unlock()
log.Debugf("Transcript: %v", powtapp.Transcript().OutputTranscriptToAudit())
conn.Close()
return nil
}
}
}
log.Debugf("Error making payment: to %v %v", ta.tokenServiceOnion, err)
return err