diff --git a/hotspot/HotspotManager.cs b/hotspot/HotspotManager.cs index 2d04537..a44ad1c 100644 --- a/hotspot/HotspotManager.cs +++ b/hotspot/HotspotManager.cs @@ -14,25 +14,36 @@ using ln.types.btree; using ln.types.net; using System.Collections.Generic; using System.IO; +using skyspot.radius; +using System.Linq; namespace skyspot.hotspot { public class HotspotManager { public string BasePath { get; private set; } = "/var/cache/ln.skyspot"; + public RadiusSecretsStore SecretsStore { get; private set; } + ODB odb; public ODBCollection hotspotNetworks { get; private set; } + public ODBCollection radiusSecretsCollection; - - Dictionary runtimes = new Dictionary(); + Dictionary instances = new Dictionary(); public HotspotManager() { odb = new ODB(BasePath); hotspotNetworks = odb.GetCollection(); + radiusSecretsCollection = odb.GetCollection(); + SecretsStore = radiusSecretsCollection.FirstOrDefault(); + if (SecretsStore == null) + SecretsStore = new RadiusSecretsStore(); } + public void SaveSecretsStore() => radiusSecretsCollection.Upsert(SecretsStore); + + class HotspotRuntime { diff --git a/hotspot/locator/MACLocation.cs b/hotspot/locator/MACLocation.cs new file mode 100644 index 0000000..45c7e21 --- /dev/null +++ b/hotspot/locator/MACLocation.cs @@ -0,0 +1,38 @@ +using System; +using ln.types.odb.attributes; +using ln.types.net; +namespace skyspot.hotspot.locator +{ + public class MACLocation + { + [DocumentID] + Guid ID = Guid.NewGuid(); + + public MAC ClientMAC { get; } + public String ClientLocator { get; } + + public DateTimeOffset Created { get; private set; } + public DateTimeOffset ValidThrough { get; set; } + + private MACLocation() + { + Created = DateTimeOffset.Now; + ValidThrough = Created + TimeSpan.FromHours(1); + } + + public MACLocation(MAC clientMAC,string locator) + :this() + { + ClientMAC = clientMAC; + ClientLocator = locator; + } + + public void Release() + { + ValidThrough = DateTimeOffset.Now; + } + + public bool IsValid => ValidThrough > DateTimeOffset.Now; + + } +} diff --git a/radius/RadiusSecretsStore.cs b/radius/RadiusSecretsStore.cs new file mode 100644 index 0000000..64444f1 --- /dev/null +++ b/radius/RadiusSecretsStore.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using ln.types.net; +using ln.types.odb.attributes; +namespace skyspot.radius +{ + public class RadiusSecretsStore + { + [DocumentID] + Guid ID = Guid.NewGuid(); + + public byte[] DefaultSecret { get; set; } + + Dictionary secrets = new Dictionary(); + + public RadiusSecretsStore() + { + } + + public bool ContainsEndpoint(Endpoint4 endpoint) => secrets.ContainsKey(endpoint); + public IEnumerable Endpoints => secrets.Keys; + + public byte[] LookupSecret(Endpoint4 endpoint) + { + if (secrets.ContainsKey(endpoint)) + return secrets[endpoint]; + return DefaultSecret; + } + + public byte[] GetSecret(Endpoint4 endpoint) => secrets[endpoint]; + public void SetSecret(Endpoint4 endpoint, byte[] secret) => secrets[endpoint] = secret; + public void RemoveSecret(Endpoint4 endpoint) => secrets.Remove(endpoint); + } +} diff --git a/session/SessionManager.cs b/session/SessionManager.cs index 9df40b4..5f35d82 100644 --- a/session/SessionManager.cs +++ b/session/SessionManager.cs @@ -16,12 +16,15 @@ using System.Net; using ln.logging; using ln.types.odb; using ln.types.odb.mapped; +using skyspot.radius; namespace skyspot.session { public class SessionManager { - byte[] defaultSecret = new byte[] { 0x41, 0x42, 0x43 }; - RadiusServer radiusServer; + public RadiusSecretsStore SecretsStore { get; private set; } + + RadiusServer accountingRadius; + RadiusServer locatorRadius; public SessionManager() { @@ -35,8 +38,8 @@ namespace skyspot.session private void InitializeRadius() { - radiusServer = new RadiusServer(new IPEndPoint(IPAddress.Any,1812)); - radiusServer.LookupSecret = LookupRadiusSecret; + accountingRadius= new RadiusServer(new IPEndPoint(IPAddress.Any,1812)); + .LookupSecret = LookupRadiusSecret; radiusServer.MessageReceived = RadiusMessageReceived; } diff --git a/skyspot.csproj b/skyspot.csproj index 9efc709..0f98767 100644 --- a/skyspot.csproj +++ b/skyspot.csproj @@ -47,6 +47,8 @@ + + @@ -85,6 +87,8 @@ + +