-
Notifications
You must be signed in to change notification settings - Fork 100
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
RPC-JSON over WebSockets #847
Closed
Closed
Changes from 45 commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
0f70f8d
init project websocketserver
cschuchardt88 e2de661
Updated json
cschuchardt88 35d7c70
dotnet format
cschuchardt88 983d543
Removed unused code
cschuchardt88 528e1ca
Fixed codeql
cschuchardt88 cf968be
Added EnableBasicAuthentication, User, Pass, AllowOrigins and Concurr…
cschuchardt88 5a76fab
Updated SslCert to SslCertFile
cschuchardt88 9410d92
fix codeql again
cschuchardt88 665e4f5
revert *.csproj files configuation
cschuchardt88 e5a0e29
code clean up
cschuchardt88 8c8f611
fixed format
cschuchardt88 8e1c9f7
format again
cschuchardt88 e20e84c
one more time
cschuchardt88 ec72689
one more (project files) dotnet format dont work on them
cschuchardt88 8d10b0c
Add new features
cschuchardt88 5df1de0
changed function to static
cschuchardt88 03015d7
dotnet format
cschuchardt88 5acf717
Merge branch 'master' into WebSocketServer
cschuchardt88 2f8d05f
Fixed disconnect issue
cschuchardt88 67e0f91
Build out basic blockchain methods for getting data
cschuchardt88 fc67dee
INIT PROJECT
cschuchardt88 f21c286
Fixed MERGE
cschuchardt88 4bc67df
Fixed sln file
cschuchardt88 2597889
Added basic protocol methods for the node information.
cschuchardt88 8b240b5
Add mempool and code clean up
cschuchardt88 207fe70
Merge branch 'master' into WebSocketServer
cschuchardt88 f54ed8f
Code clean up
cschuchardt88 86d915d
Touched up code and reuseable with ws protocol changes
cschuchardt88 3d999cb
Updated SendAllJson, added pluginId
cschuchardt88 baaccad
Added Invoke Contract
cschuchardt88 b7af661
Fixed exception null in InvokeContract
cschuchardt88 19b8da6
Fixed gasconsumed in InvokeContract method, was output as string, now…
cschuchardt88 987dc46
Remove virtual methods from WebSocketConnection
cschuchardt88 8e53db8
Fixed IEquatable for WebSocketResponseMessage
cschuchardt88 f6ff6a8
Add some wallet methods to the api, not completed yet.
cschuchardt88 53cefdf
Added more wallet methods
cschuchardt88 3bb4306
Add more wallet methods
cschuchardt88 1832fd8
finsished the wallet api
cschuchardt88 8dcb91e
Update WalletSessionManager.cs
cschuchardt88 074649f
Remove TClient and null checks
shargon 8927853
Prevent problems with date seasons changes
shargon 32a867e
Revert "Remove TClient and null checks"
cschuchardt88 1ec7644
Fixed WebSocketClient
cschuchardt88 ecbb806
Fixed error
cschuchardt88 307d263
Made project nullable
cschuchardt88 23d9a34
Update BlockchainMethods.cs
cschuchardt88 ac6526f
Merge branch 'master' into WebSocketServer
cschuchardt88 580b864
format
cschuchardt88 7d8f492
RPC-JSON added still needs programming
cschuchardt88 35675e2
Added event system
cschuchardt88 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Neo.Wallets; | ||
using System; | ||
|
||
namespace Neo.Plugins | ||
{ | ||
public class WalletSession | ||
{ | ||
public Wallet Wallet { get; private init; } | ||
public DateTime Expires { get; private set; } | ||
|
||
public WalletSession( | ||
Wallet wallet) | ||
{ | ||
Wallet = wallet; | ||
ResetExpiration(); | ||
} | ||
|
||
public void ResetExpiration() => | ||
Expires = DateTime.UtcNow.AddSeconds(WebSocketServerSettings.Current?.WalletSessionTimeout ?? WebSocketServerSettings.Default.WalletSessionTimeout); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Neo.Plugins | ||
{ | ||
public class WalletSessionManager : ConcurrentDictionary<Guid, WalletSession> | ||
{ | ||
private readonly PeriodicTimer _timer; | ||
|
||
public WalletSessionManager() | ||
{ | ||
_timer = new(TimeSpan.FromSeconds(1)); | ||
_ = Task.Run(SessionTimeoutAsync); | ||
} | ||
|
||
private async Task SessionTimeoutAsync() | ||
{ | ||
while (await _timer.WaitForNextTickAsync()) | ||
{ | ||
var killAll = this.Where(w => w.Value.Expires <= DateTime.UtcNow) | ||
.Select(s => Task.Run(() => | ||
{ | ||
TryRemove(s); | ||
})); | ||
await Task.WhenAll(killAll); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using Neo.Json; | ||
using System; | ||
using System.Net.WebSockets; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Neo.Plugins | ||
{ | ||
internal class WebSocketClient : IDisposable, IEquatable<WebSocketClient> | ||
{ | ||
public WebSocket? Socket { get; init; } | ||
|
||
public bool IsConnected => | ||
Socket != null && | ||
Socket.State == WebSocketState.Open; | ||
|
||
public void Dispose() | ||
{ | ||
Socket?.Dispose(); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
public async Task SendJsonAsync(JToken message) | ||
{ | ||
if (IsConnected) | ||
{ | ||
await Socket!.SendAsync( | ||
new(Encoding.UTF8.GetBytes(message.ToString())), | ||
WebSocketMessageType.Text, | ||
true, | ||
CancellationToken.None).ConfigureAwait(false); | ||
} | ||
} | ||
|
||
public async Task CloseAsync(WebSocketCloseStatus status) | ||
{ | ||
if (Socket == null) | ||
return; | ||
switch (Socket.State) | ||
{ | ||
case WebSocketState.Connecting: | ||
case WebSocketState.Open: | ||
await Socket.CloseOutputAsync(status, string.Empty, CancellationToken.None).ConfigureAwait(false); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
#region IEquatable | ||
|
||
public bool Equals(WebSocketClient? other) => | ||
ReferenceEquals(Socket, other?.Socket); | ||
|
||
public override int GetHashCode() => | ||
HashCode.Combine(this, Socket); | ||
|
||
public override bool Equals(object? obj) | ||
{ | ||
if (ReferenceEquals(obj, this)) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (obj is not WebSocketClient wsObj) | ||
return false; | ||
return Equals(wsObj); | ||
} | ||
|
||
public static bool operator ==(WebSocketClient left, WebSocketClient right) | ||
{ | ||
if (left as object is null || right as object is null) | ||
return Equals(left, right); | ||
return left.Equals(right); | ||
} | ||
|
||
public static bool operator !=(WebSocketClient left, WebSocketClient right) | ||
{ | ||
if (left as object is null || right as object is null) | ||
return Equals(left, right) == false; | ||
return left.Equals(right) == false; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this with ?, only is needed because you want a T type that we don't need
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand. Referring to
T
type; we do need it! This aBASE
CLASS. NOT DOING SO WILL LIMIT AND FLAW EXPANDABLE OF AND POINT OF THIS LIBRARY. If we want to keep limiting theapi
we can do that. Just look atRpcServer
is outdated and cannot be expanded or updated easily. Which is why no one touches it and in the state it's in now.