Serverless scaling and work to authorizer
This commit is contained in:
@ -6,19 +6,9 @@ namespace authorizer
|
||||
class Program
|
||||
{
|
||||
static AuthServer server;
|
||||
static Redis redis;
|
||||
static void Main(string[] args)
|
||||
{
|
||||
redis = new Redis(Environment.GetEnvironmentVariable("REDIS_HOSTNAME"));
|
||||
|
||||
redis.SetTest();
|
||||
|
||||
Thread.Sleep(100);
|
||||
|
||||
redis.GetTest();
|
||||
|
||||
|
||||
/* server = new AuthServer();
|
||||
server = new AuthServer();
|
||||
|
||||
server.Start();
|
||||
|
||||
@ -28,7 +18,7 @@ namespace authorizer
|
||||
input = Console.ReadLine();
|
||||
}
|
||||
while(input != "stop");
|
||||
server.Stop(); */
|
||||
server.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ using StackExchange.Redis;
|
||||
class Redis
|
||||
{
|
||||
private ConnectionMultiplexer muxer;
|
||||
private IDatabase conn;
|
||||
public IDatabase conn;
|
||||
private string hostname;
|
||||
private int port;
|
||||
public Redis(string host = "127.0.0.1", int p = 6379)
|
||||
@ -25,18 +25,6 @@ class Redis
|
||||
Console.WriteLine("Connected to redis server!");
|
||||
}
|
||||
|
||||
public void SetTest()
|
||||
{
|
||||
string test_val = "Potato";
|
||||
conn.StringSet("test_val", test_val);
|
||||
Console.WriteLine("Set value to: " + test_val);
|
||||
}
|
||||
|
||||
public void GetTest()
|
||||
{
|
||||
Console.WriteLine("Value is: " + conn.StringGet("test_val"));
|
||||
}
|
||||
|
||||
~Redis()
|
||||
{
|
||||
muxer.Close();
|
||||
|
@ -1,44 +1,86 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
using Amazon.ECS;
|
||||
using Amazon.ECS.Model;
|
||||
using System.Collections.Generic;
|
||||
class AuthServer
|
||||
{
|
||||
private int port;
|
||||
private IPAddress address;
|
||||
private TcpListener server;
|
||||
private Thread thread;
|
||||
private bool running = false;
|
||||
private int port;
|
||||
private Thread thread;
|
||||
private IPAddress address;
|
||||
|
||||
// Core objects
|
||||
private TcpListener server;
|
||||
private Redis redis;
|
||||
private AmazonECSClient ecs;
|
||||
|
||||
|
||||
public AuthServer(string addr = "0.0.0.0", int p = 7778)
|
||||
{
|
||||
port = p;
|
||||
address = IPAddress.Parse(addr);
|
||||
|
||||
redis = new Redis(Environment.GetEnvironmentVariable("REDIS_HOSTNAME"));
|
||||
server = new TcpListener(address, port);
|
||||
ecs = new AmazonECSClient();
|
||||
}
|
||||
private void ServerLoop()
|
||||
{
|
||||
while(running)
|
||||
{
|
||||
Console.WriteLine("Waiting for a connection...");
|
||||
|
||||
TcpClient client = server.AcceptTcpClient();
|
||||
Console.WriteLine("Connected!");
|
||||
|
||||
Byte[] bytes = new byte[256];
|
||||
String data = null;
|
||||
|
||||
NetworkStream stream = client.GetStream();
|
||||
|
||||
int i;
|
||||
|
||||
while((i = stream.Read(bytes, 0, bytes.Length)) != 0)
|
||||
try
|
||||
{
|
||||
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
|
||||
Console.WriteLine("Recieved: {0}", data);
|
||||
//Wait for connection
|
||||
TcpClient client = server.AcceptTcpClient();
|
||||
//Get remote address
|
||||
IPEndPoint endPoint = (IPEndPoint) client.Client.RemoteEndPoint;
|
||||
Console.WriteLine(endPoint.Address.ToString() + " connected!");
|
||||
|
||||
//Create streams
|
||||
NetworkStream stream = client.GetStream();
|
||||
StreamWriter writer = new StreamWriter(stream);
|
||||
|
||||
Byte[] bytes = new byte[256];
|
||||
String data = null;
|
||||
|
||||
|
||||
writer.Write("Hey there bud!");
|
||||
writer.Flush();
|
||||
Console.WriteLine("HERE");
|
||||
|
||||
byte[] sendBytes = System.Text.Encoding.ASCII.GetBytes("GET / HTTP/1.1");
|
||||
stream.Write(sendBytes, 0, sendBytes.Length);
|
||||
client.Client.Send(sendBytes);
|
||||
|
||||
|
||||
//BinaryWriter writer = new BinaryWriter(stream);
|
||||
//writer.Write("TEST");
|
||||
|
||||
|
||||
|
||||
int i;
|
||||
|
||||
while((i = stream.Read(bytes, 0, bytes.Length)) != 0)
|
||||
{
|
||||
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
|
||||
Console.WriteLine("Recieved: {0}", data);
|
||||
|
||||
|
||||
}
|
||||
|
||||
client.Close();
|
||||
Console.WriteLine("Client disconnected");
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Console.WriteLine("Fatal exception: " + e.ToString());
|
||||
}
|
||||
|
||||
client.Close();
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,6 +91,7 @@ class AuthServer
|
||||
ThreadStart entrypoint = new ThreadStart(ServerLoop);
|
||||
thread = new Thread(entrypoint);
|
||||
thread.Start();
|
||||
Console.WriteLine("Waiting for a connection...");
|
||||
}
|
||||
public void Stop()
|
||||
{
|
||||
@ -56,6 +99,7 @@ class AuthServer
|
||||
}
|
||||
public void ForceStop()
|
||||
{
|
||||
thread.Join();
|
||||
running = false;
|
||||
thread.Abort();
|
||||
}
|
||||
}
|
@ -6,6 +6,8 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AWSSDK.Core" Version="3.5.0-beta" />
|
||||
<PackageReference Include="AWSSDK.ECS" Version="3.5.0-beta" />
|
||||
<PackageReference Include="StackExchange.Redis" Version="2.1.39" />
|
||||
</ItemGroup>
|
||||
|
||||
|
Reference in New Issue
Block a user