Fixup Token Requests
This commit is contained in:
parent
a28896c293
commit
271ecdb8ec
|
@ -159,7 +159,6 @@ type ModifyServers interface {
|
||||||
|
|
||||||
// SendMessages enables a caller to sender messages to a contact
|
// SendMessages enables a caller to sender messages to a contact
|
||||||
type SendMessages interface {
|
type SendMessages interface {
|
||||||
|
|
||||||
SendMessage(handle string, message string) error
|
SendMessage(handle string, message string) error
|
||||||
|
|
||||||
SendGetValToPeer(string, string, string)
|
SendGetValToPeer(string, string, string)
|
||||||
|
|
|
@ -450,7 +450,7 @@ func (e *engine) sendGetValToPeer(eventID, onion, scope, path string) error {
|
||||||
return err
|
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})
|
return e.sendPeerMessage(onion, model3.PeerMessage{ID: eventID, Context: event.ContextGetVal, Data: message})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -528,7 +528,7 @@ func (e *engine) handlePeerMessage(hostname string, eventID string, context stri
|
||||||
e.handlePeerRetVal(hostname, reqStr, message)
|
e.handlePeerRetVal(hostname, reqStr, message)
|
||||||
e.getValRequests.Delete(hostname + eventID)
|
e.getValRequests.Delete(hostname + eventID)
|
||||||
} else {
|
} 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 {
|
} else if context == event.ContextGetVal {
|
||||||
var getVal peerGetVal
|
var getVal peerGetVal
|
||||||
|
|
|
@ -72,7 +72,6 @@ func (ta *TokenBoardClient) Init(connection tapir.Connection) {
|
||||||
go ta.Listen()
|
go ta.Listen()
|
||||||
// Optimistically acquire many tokens for this server...
|
// Optimistically acquire many tokens for this server...
|
||||||
go ta.MakePayment()
|
go ta.MakePayment()
|
||||||
go ta.MakePayment()
|
|
||||||
ta.Replay()
|
ta.Replay()
|
||||||
} else {
|
} else {
|
||||||
connection.Close()
|
connection.Close()
|
||||||
|
@ -179,11 +178,15 @@ func (ta *TokenBoardClient) MakePayment() error {
|
||||||
powTokenApp := new(applications.ApplicationChain).
|
powTokenApp := new(applications.ApplicationChain).
|
||||||
ChainApplication(new(applications.ProofOfWorkApplication), applications.SuccessfulProofOfWorkCapability).
|
ChainApplication(new(applications.ProofOfWorkApplication), applications.SuccessfulProofOfWorkCapability).
|
||||||
ChainApplication(tokenApplication, applications.HasTokensCapability)
|
ChainApplication(tokenApplication, applications.HasTokensCapability)
|
||||||
client.Connect(ta.tokenServiceOnion, powTokenApp)
|
|
||||||
log.Debugf("Waiting for successful PoW Auth...")
|
log.Debugf("Waiting for successful PoW Auth...")
|
||||||
|
|
||||||
|
connected, err := client.Connect(ta.tokenServiceOnion, powTokenApp)
|
||||||
|
if connected == true && err == nil {
|
||||||
conn, err := client.WaitForCapabilityOrClose(ta.tokenServiceOnion, applications.HasTokensCapability)
|
conn, err := client.WaitForCapabilityOrClose(ta.tokenServiceOnion, applications.HasTokensCapability)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
powtapp, _ := conn.App().(*applications.TokenApplication)
|
powtapp, ok := conn.App().(*applications.TokenApplication)
|
||||||
|
if ok {
|
||||||
// Update tokens...we need a lock here to prevent SpendToken from modifying the tokens
|
// Update tokens...we need a lock here to prevent SpendToken from modifying the tokens
|
||||||
// during this process..
|
// during this process..
|
||||||
log.Debugf("Updating Tokens")
|
log.Debugf("Updating Tokens")
|
||||||
|
@ -194,6 +197,8 @@ func (ta *TokenBoardClient) MakePayment() error {
|
||||||
conn.Close()
|
conn.Close()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
log.Debugf("Error making payment: to %v %v", ta.tokenServiceOnion, err)
|
log.Debugf("Error making payment: to %v %v", ta.tokenServiceOnion, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue