Skip to content

Commit

Permalink
Fix Swarm() hangs
Browse files Browse the repository at this point in the history
  • Loading branch information
longfin committed Apr 1, 2019
1 parent 452b28c commit e8cdf71
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ To be released.
already has and deal with only longer (higher) blocks.
- Fixed a bug that occured when `Swarm` was handling multiple responses at the
same time.
- Fixes a bug that hangs when calling the `Swarm` constructor in certain
runtimes. (e.g. Unity3d)
- Removed `AddressTransactionSet` which handles handle `Address` to
`IEnumerable<TxId>` indices, and the following methods in `IStore`:
- `IStore.IterateAddresses()`
Expand Down
18 changes: 10 additions & 8 deletions Libplanet/Net/Swarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ public partial class Swarm : ICollection<Peer>, IDisposable
private readonly AsyncLock _receiveMutex;
private readonly AsyncLock _blockSyncMutex;
private readonly string _host;
private readonly TurnClient _turnClient;
private readonly IList<IceServer> _iceServers;

private readonly ILogger _logger;

private TaskCompletionSource<object> _runningEvent;
private int? _listenPort;
private TurnClient _turnClient;

private NetMQQueue<Message> _replyQueue;

Expand Down Expand Up @@ -115,15 +116,11 @@ public Swarm(
EndPoint = new DnsEndPoint(_host, listenPort.Value);
}

if (iceServers != null)
{
_turnClient = IceServer.CreateTurnClient(iceServers).Result;
}

if (_host == null && _turnClient == null)
_iceServers = iceServers?.ToList();
if (_host == null && _iceServers == null)
{
throw new ArgumentException(
$"Swarm needs {nameof(host)} or {iceServers}.");
$"Swarm needs {nameof(host)} or {nameof(iceServers)}.");
}

string loggerId = _privateKey.PublicKey.ToAddress().ToHex();
Expand Down Expand Up @@ -399,6 +396,11 @@ public async Task StartAsync<T>(
throw new SwarmException("Swarm is already running.");
}

if (_iceServers != null)
{
_turnClient = await IceServer.CreateTurnClient(_iceServers);
}

if (_listenPort == null)
{
_listenPort = _router.BindRandomPort("tcp://*");
Expand Down

0 comments on commit e8cdf71

Please sign in to comment.