Skip to content

Commit

Permalink
Implemented bandwidth counter
Browse files Browse the repository at this point in the history
  • Loading branch information
Elycin committed Dec 20, 2017
1 parent bb89e1a commit 5d24398
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions PoolOverSocks5/RelayHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ class RelayHandler
public ManualResetEvent allDone = new ManualResetEvent(false);

// Incoming data from the client.
public static string data = null;
private static string data = null;

// Client that will connect to the Socks5 Proxy.
public Socks5ProxyClient relayClientProxy;
private Socks5ProxyClient relayClientProxy;

// TCP client to the pool.
public TcpClient relayClient;
private TcpClient relayClient;

// the default buffer size for network transfers.
public Int32 buffersize = 4096; //bytes

private decimal bandwidthUsed = 0.0m;

public RelayHandler(ConfigurationHandler configuration)
{
// Inherit from the main class.
Expand Down Expand Up @@ -84,8 +86,9 @@ public void Work()
// Only process if there's data available.
if (handler.Available != 0) {
int bytesReceived = handler.Receive(bytes);
bandwidthUsed += bytesReceived;
data = Encoding.ASCII.GetString(bytes, 0, bytesReceived);
Console.WriteLine("MINER SENT: '{0}'", data.Substring(0, data.Length - 1));
Console.WriteLine("Miner:\n{0}", data.Substring(0, data.Length - 1));
byte[] message = Encoding.ASCII.GetBytes(data);
relayClient.Client.Send(message);
}
Expand All @@ -106,9 +109,11 @@ public void Work()
if (relayClient.Available != 0) {
byte[] relayRecv = new byte[buffersize];
int bytesReceived = relayClient.Client.Receive(relayRecv);
bandwidthUsed += bytesReceived;
String dataInFromProxy = Encoding.ASCII.GetString(relayRecv, 0, bytesReceived);
Console.WriteLine("PROXY RESPONSE: '{0}'", dataInFromProxy.Substring(0, dataInFromProxy.Length - 1));
Console.WriteLine("Proxy Response:\n{0}", dataInFromProxy.Substring(0, dataInFromProxy.Length - 1));
handler.Send(relayRecv, 0, bytesReceived, SocketFlags.None);
Console.WriteLine("Bandwidth Usage: {0} MB", Decimal.Round((bandwidthUsed / 1024 / 1024), 4).ToString());
}
} else {
// Client has disconnected - close the sockets and restart.
Expand Down
Binary file modified PoolOverSocks5/bin/Debug/netcoreapp2.0/PoolOverSocks5.dll
Binary file not shown.
Binary file modified PoolOverSocks5/bin/Debug/netcoreapp2.0/PoolOverSocks5.pdb
Binary file not shown.
Binary file modified PoolOverSocks5/obj/Debug/netcoreapp2.0/PoolOverSocks5.dll
Binary file not shown.
Binary file modified PoolOverSocks5/obj/Debug/netcoreapp2.0/PoolOverSocks5.pdb
Binary file not shown.

0 comments on commit 5d24398

Please sign in to comment.