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

Add connection timeout configuration #124

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion WalletConnectSharp.Core/Controllers/Relayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ public string Context
/// </summary>
public IJsonRpcProvider Provider { get; private set; }

/// <summary>
/// How long the <see cref="IRelayer"/> should wait before throwing a <see cref="TimeoutException"/> during
/// the connection phase. If this field is null, then the timeout will be infinite.
/// </summary>
public TimeSpan? ConnectionTimeout { get; set; }

/// <summary>
/// Whether this Relayer is connected
/// </summary>
Expand Down Expand Up @@ -133,6 +139,8 @@ public Relayer(RelayerOptions opts)
}

projectId = opts.ProjectId;

ConnectionTimeout = opts.ConnectionTimeout;
}

/// <summary>
Expand Down Expand Up @@ -404,7 +412,11 @@ async void Task2()
this.Events.ListenForOnce<object>(RelayerEvents.TransportClosed, RejectTransportOpen);
try
{
await this.Provider.Connect().WithTimeout(TimeSpan.FromSeconds(5), "socket stalled");
var connectionTask = this.Provider.Connect();
if (ConnectionTimeout != null)
connectionTask = connectionTask.WithTimeout((TimeSpan)ConnectionTimeout, "socket stalled");

await connectionTask;
task2.TrySetResult(true);
}
finally
Expand Down
6 changes: 6 additions & 0 deletions WalletConnectSharp.Core/Interfaces/IRelayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public interface IRelayer : IEvents, IModule
/// </summary>
public IJsonRpcProvider Provider { get; }

/// <summary>
/// How long the <see cref="IRelayer"/> should wait before throwing a <see cref="TimeoutException"/> during
/// the connection phase. If this field is null, then the timeout will be infinite.
/// </summary>
public TimeSpan? ConnectionTimeout { get; set; }

/// <summary>
/// Whether this Relayer is connected to the WalletConnect relay server
/// </summary>
Expand Down
8 changes: 7 additions & 1 deletion WalletConnectSharp.Core/Models/CoreOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public class CoreOptions
/// with either the KeyChain option or a default keychain
/// </summary>
public ICrypto CryptoModule;


/// <summary>
/// How long the <see cref="IRelayer"/> should wait before throwing a <see cref="TimeoutException"/> during
/// the connection phase. If this field is null, then the timeout will be infinite.
/// </summary>
public TimeSpan? ConnectionTimeout = TimeSpan.FromSeconds(30);

}
}
6 changes: 6 additions & 0 deletions WalletConnectSharp.Core/Models/Relay/RelayerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,11 @@ public class RelayerOptions
/// </summary>
[JsonProperty("projectId")]
public string ProjectId { get; set; }

/// <summary>
/// How long the <see cref="IRelayer"/> should wait before throwing a <see cref="TimeoutException"/> during
/// the connection phase. If this field is null, then the timeout will be infinite.
/// </summary>
public TimeSpan? ConnectionTimeout = TimeSpan.FromSeconds(30);
}
}
3 changes: 2 additions & 1 deletion WalletConnectSharp.Core/WalletConnectCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ public WalletConnectCore(CoreOptions options = null)
{
Core = this,
ProjectId = ProjectId,
RelayUrl = options.RelayUrl
RelayUrl = options.RelayUrl,
ConnectionTimeout = options.ConnectionTimeout,
});

MessageHandler = new TypedMessageHandler(this);
Expand Down
Loading