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