Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-ordering Swarm<T>.StartAsync() #424

Merged
merged 1 commit into from Aug 12, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -93,6 +93,8 @@ To be released.
disconnected while receiving. [[#416]]
- Fixed a bug that `Swarm<T>.PreloadAsync()` had been processed even if there
is no appropriate peer. [[#418]]
- Fixed a bug that TURN relay connection had disconnected when preloading
took a long time. [[#424]]

[#319]: https://github.com/planetarium/libplanet/issues/319
[#343]: https://github.com/planetarium/libplanet/pull/343
@@ -122,6 +124,7 @@ To be released.
[#416]: https://github.com/planetarium/libplanet/pull/416
[#417]: https://github.com/planetarium/libplanet/pull/417
[#418]: https://github.com/planetarium/libplanet/pull/418
[#424]: https://github.com/planetarium/libplanet/pull/424
[LiteDB #1268]: https://github.com/mbdavid/LiteDB/issues/1268


@@ -435,12 +435,18 @@ private set

_logger.Information($"Listen on {_listenPort}");

_workerCancellationTokenSource = new CancellationTokenSource();
CancellationToken workerCancellationToken =
CancellationTokenSource.CreateLinkedTokenSource(
_workerCancellationTokenSource.Token, cancellationToken
).Token;
_cancellationToken = workerCancellationToken;
var tasks = new List<Task>();
var behindNAT = false;

if (!(_turnClient is null))
{
_publicIPAddress = (await _turnClient.GetMappedAddressAsync())
.Address;
_publicIPAddress = (await _turnClient.GetMappedAddressAsync()).Address;

if (await _turnClient.IsBehindNAT())
{
@@ -453,42 +459,28 @@ private set
IPEndPoint turnEp = await _turnClient.AllocateRequestAsync(
TurnAllocationLifetime
);
EndPoint = new DnsEndPoint(
turnEp.Address.ToString(), turnEp.Port);
EndPoint = new DnsEndPoint(turnEp.Address.ToString(), turnEp.Port);

tasks.Add(BindingProxies(_cancellationToken));
tasks.Add(RefreshAllocate(_cancellationToken));
tasks.Add(RefreshPermissions(_cancellationToken));
}
else
{
EndPoint = new DnsEndPoint(_host, _listenPort.Value);
}

try
using (await _runningMutex.LockAsync())
{
_workerCancellationTokenSource = new CancellationTokenSource();
CancellationToken workerCancellationToken =
CancellationTokenSource.CreateLinkedTokenSource(
_workerCancellationTokenSource.Token, cancellationToken
).Token;
_cancellationToken = workerCancellationToken;

using (await _runningMutex.LockAsync())
{
Running = true;
await PreloadAsync(render: true, cancellationToken: _cancellationToken);
}

var tasks = new List<Task>
{
RepeatDeltaDistributionAsync(distributeInterval, _cancellationToken),
BroadcastTxAsync(broadcastTxInterval, _cancellationToken),
Task.Run(() => _poller.Run(), _cancellationToken),
};
await PreloadAsync(render: true, cancellationToken: _cancellationToken);
Running = true;
}

if (behindNAT)
{
tasks.Add(BindingProxies(_cancellationToken));
tasks.Add(RefreshAllocate(_cancellationToken));
tasks.Add(RefreshPermissions(_cancellationToken));
}
try
{
tasks.Add(RepeatDeltaDistributionAsync(distributeInterval, _cancellationToken));
tasks.Add(BroadcastTxAsync(broadcastTxInterval, _cancellationToken));
tasks.Add(Task.Run(() => _poller.Run(), _cancellationToken));

await await Task.WhenAny(tasks);
}
@@ -498,9 +490,7 @@ private set
}
catch (Exception e)
{
_logger.Error(
e,
"An unexpected exception occured during StartAsync()");
_logger.Error(e, "An unexpected exception occured during StartAsync()");
throw;
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.