Exemplo n.º 1
0
// FetchMessage fetches a message from the accountserver.
func FetchMessage(privkey *[ed25519.PrivateKeySize]byte, messageID []byte, server string, cacert []byte) ([]byte, error) {
	var authtoken []byte
	var err error
	var message []byte
	lastcounter := uint64(times.NowNano())
	pubkey := splitKey(privkey)
	i := 3 // This should skip error and a collision, but stop if it's an ongoing parallel access
CallLoop:
	for {
		if authtoken == nil {
			authtoken = walletauth.CreateToken(pubkey, privkey, lastcounter+1)
		}
		message, lastcounter, err = fetchmessage(messageID, authtoken, server, cacert)
		if err == walletauth.ErrReplay {
			authtoken = nil
			if i > 0 {
				i--
				continue CallLoop
			}
		}
		break CallLoop
	}
	return message, err

}
Exemplo n.º 2
0
// DeleteAccount deletes the account of privkey on server.
func DeleteAccount(privkey *[ed25519.PrivateKeySize]byte, server string, cacert []byte) (err error) {
	var authtoken []byte
	var result bool
	lastcounter := uint64(times.NowNano())
	pubkey := splitKey(privkey)
	i := 3 // This should skip error and a collision, but stop if it's an ongoing parallel access
CallLoop:
	for {
		if authtoken == nil {
			authtoken = walletauth.CreateToken(pubkey, privkey, lastcounter+1)
		}
		result, lastcounter, err = delAccount(authtoken, server, cacert)
		if err == walletauth.ErrReplay {
			authtoken = nil
			if i > 0 {
				i--
				continue CallLoop
			}
		}
		break CallLoop
	}
	if err != nil {
		return err
	}
	if result {
		return nil
	}
	return ErrNoMatch
}
Exemplo n.º 3
0
// ListMessages gets the messages for account identified by privkey.
func ListMessages(privkey *[ed25519.PrivateKeySize]byte, lastMessageTime int64, server string, cacert []byte) (messages []MessageMeta, err error) {
	var authtoken []byte
	lastcounter := uint64(times.NowNano())
	pubkey := splitKey(privkey)
	i := 3 // This should skip error and a collision, but stop if it's an ongoing parallel access
CallLoop:
	for {
		if authtoken == nil {
			authtoken = walletauth.CreateToken(pubkey, privkey, lastcounter+1)
		}
		messages, lastcounter, err = listMessages(authtoken, lastMessageTime, server, cacert)
		if err == walletauth.ErrReplay {
			authtoken = nil
			if i > 0 {
				i--
				continue CallLoop
			}
		}
		break CallLoop
	}
	if err != nil {
		return nil, err
	}
	return messages, nil
}
Exemplo n.º 4
0
// PayAccount makes a pay call to server (or selects a new one) to create or
// extend an account identified by privkey.
func PayAccount(privkey *[ed25519.PrivateKeySize]byte, paytoken []byte, serverKnown string, cacert []byte) (server string, err error) {
	var authtoken []byte
	lastcounter := uint64(times.NowNano())
	pubkey := splitKey(privkey)
	i := 3 // This should skip error and a collision, but stop if it's an ongoing parallel access
CallLoop:
	for {
		if authtoken == nil {
			authtoken = walletauth.CreateToken(pubkey, privkey, lastcounter+1)
		}
		server, lastcounter, err = payAccount(authtoken, paytoken, serverKnown, cacert)
		if err == walletauth.ErrReplay {
			authtoken = nil
			if i > 0 {
				i--
				continue CallLoop
			}
		}
		break CallLoop
	}
	return server, err
}
Exemplo n.º 5
0
// GetBalance inquires the wallet service for the client's balance. It tries to escape replay errors.
func (wc *WalletClient) GetBalance() (SubscriptionTokens, PrepayTokens, LastSubscribeLoad uint64, err error) {
	lastcounter := wc.LastAuthCounter
	i := 3 // This should skip error and a collision, but stop if it's an ongoing parallel access
CallLoop:
	for {
		authtoken := wc.LastAuthToken
		if authtoken == nil {
			authtoken = walletauth.CreateToken(wc.PubKey, wc.PrivKey, lastcounter+1)
		}
		SubscriptionTokens, PrepayTokens, LastSubscribeLoad, lastcounter, err = wc.getBalance(authtoken)
		if err == walletauth.ErrReplay {
			wc.LastAuthCounter = lastcounter
			if i > 0 {
				i--
				continue CallLoop
			}
		}
		if err != nil {
			wc.LastAuthToken = authtoken
		}
		break CallLoop
	}
	return SubscriptionTokens, PrepayTokens, LastSubscribeLoad, err
}
Exemplo n.º 6
0
// GetToken gets a token for usage from the wallet service.
func (wc *WalletClient) GetToken(usage string) (token, params, pubKeyUsed []byte, err error) {
	lastcounter := wc.LastAuthCounter
	i := 3 // This should skip error and a collision, but stop if it's an ongoing parallel access
CallLoop:
	for {
		authtoken := wc.LastAuthToken
		if authtoken == nil {
			authtoken = walletauth.CreateToken(wc.PubKey, wc.PrivKey, lastcounter+1)
		}
		token, params, pubKeyUsed, lastcounter, err = wc.getToken(usage, authtoken)
		if err == walletauth.ErrReplay {
			wc.LastAuthCounter = lastcounter
			if i > 0 {
				i--
				continue CallLoop
			}
		}
		if err != nil {
			wc.LastAuthToken = authtoken
		}
		break CallLoop
	}
	return token, params, pubKeyUsed, err
}