Check for Duplicates...
This commit is contained in:
parent
83bf6559a2
commit
7682351753
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue