master
Harald Wolff 2019-05-07 12:54:48 +02:00
parent d270f1835b
commit 98e39c8a26
5 changed files with 96 additions and 6 deletions

View File

@ -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<HotspotNetwork> hotspotNetworks { get; private set; }
public ODBCollection<RadiusSecretsStore> radiusSecretsCollection;
Dictionary<HotspotNetwork, HotspotRuntime> runtimes = new Dictionary<HotspotNetwork, HotspotRuntime>();
Dictionary<HotspotNetwork, HotspotRuntime> instances = new Dictionary<HotspotNetwork, HotspotRuntime>();
public HotspotManager()
{
odb = new ODB(BasePath);
hotspotNetworks = odb.GetCollection<HotspotNetwork>();
radiusSecretsCollection = odb.GetCollection<RadiusSecretsStore>();
SecretsStore = radiusSecretsCollection.FirstOrDefault();
if (SecretsStore == null)
SecretsStore = new RadiusSecretsStore();
}
public void SaveSecretsStore() => radiusSecretsCollection.Upsert(SecretsStore);
class HotspotRuntime
{

View File

@ -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;
}
}

View File

@ -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<Endpoint4, byte[]> secrets = new Dictionary<Endpoint4, byte[]>();
public RadiusSecretsStore()
{
}
public bool ContainsEndpoint(Endpoint4 endpoint) => secrets.ContainsKey(endpoint);
public IEnumerable<Endpoint4> 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);
}
}

View File

@ -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;
}

View File

@ -47,6 +47,8 @@
<Compile Include="hotspot\HotspotNetwork.cs" />
<Compile Include="hotspot\HotspotSession.cs" />
<Compile Include="hotspot\HotspotManager.cs" />
<Compile Include="hotspot\locator\MACLocation.cs" />
<Compile Include="radius\RadiusSecretsStore.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ln.http\ln.http.csproj">
@ -85,6 +87,8 @@
<Folder Include="www\system\" />
<Folder Include="www\js\" />
<Folder Include="hotspot\" />
<Folder Include="hotspot\locator\" />
<Folder Include="radius\" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />