get_or_create_usable_address returns a random choice when returning an existing unused address

This commit is contained in:
Lex Berezhny 2018-10-09 13:13:46 -04:00
parent 2723a55766
commit 689c578081

View file

@ -1,3 +1,4 @@
import random
import typing import typing
from typing import List, Dict, Tuple, Type, Optional, Any from typing import List, Dict, Tuple, Type, Optional, Any
from twisted.internet import defer from twisted.internet import defer
@ -73,9 +74,9 @@ class AddressManager:
@defer.inlineCallbacks @defer.inlineCallbacks
def get_or_create_usable_address(self) -> defer.Deferred: def get_or_create_usable_address(self) -> defer.Deferred:
addresses = yield self.get_addresses(only_usable=True, limit=1) addresses = yield self.get_addresses(only_usable=True, limit=10)
if addresses: if addresses:
return addresses[0] return random.choice(addresses)
addresses = yield self.ensure_address_gap() addresses = yield self.ensure_address_gap()
return addresses[0] return addresses[0]