Check for Duplicates...
continuous-integration/drone/pr Build is failing Details
continuous-integration/drone/push Build was killed Details

This commit is contained in:
Sarah Jamie Lewis 2021-09-09 16:27:05 -07:00
parent 83bf6559a2
commit 7682351753
1 changed files with 24 additions and 20 deletions

View File

@ -71,7 +71,7 @@ func (ta *TokenBoardClient) Init(connection tapir.Connection) {
log.Debugf("Successfully Initialized Connection")
go ta.Listen()
// Optimistically acquire many tokens for this server...
ta.MakePayment()
go ta.MakePayment()
ta.Replay()
} else {
connection.Close()
@ -181,25 +181,29 @@ func (ta *TokenBoardClient) MakePayment() error {
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)
if err == nil {
powtapp := conn.App().(*applications.TokenApplication)
if powtapp != nil {
// Update tokens...we need a lock here to prevent SpendToken from modifying the tokens
// during this process..
log.Debugf("Transcript: %v", powtapp.Transcript().OutputTranscriptToAudit())
conn.Close()
log.Debugf("Updating Tokens")
ta.tokenLock.Lock()
ta.tokens = append(ta.tokens, powtapp.Tokens...)
if len(ta.tokens) < 5 {
go ta.MakePayment()
}
ta.tokenLock.Unlock()
return nil
}
// We can't have duplicate outbounds...
conn, _ := client.GetConnection(ta.tokenServiceOnion)
for {
if conn == nil {
break
}
conn, _ = client.GetConnection(ta.tokenServiceOnion)
}
client.Connect(ta.tokenServiceOnion, powTokenApp)
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)