ln.skyspot/hotspot/HotspotManager.cs

94 lines
3.0 KiB
C#
Raw Permalink Normal View History

2019-05-07 10:21:25 +02:00
// /**
// * File: HotspotManager.cs
// * Author: haraldwolff
// *
// * This file and it's content is copyrighted by the Author and / or copyright holder.
// * Any use wihtout proper permission is illegal and may lead to legal actions.
// *
// *
// **/
using System;
2019-05-07 10:21:50 +02:00
using ln.types.odb;
using ln.types.odb.mapped;
using ln.types.btree;
using ln.types.net;
using System.Collections.Generic;
using System.IO;
2019-05-07 12:54:48 +02:00
using skyspot.radius;
using System.Linq;
2019-05-10 13:27:06 +02:00
using skyspot.session;
2019-05-07 10:21:25 +02:00
namespace skyspot.hotspot
{
public class HotspotManager
{
2019-05-07 10:21:50 +02:00
public string BasePath { get; private set; } = "/var/cache/ln.skyspot";
2019-05-07 12:54:48 +02:00
public RadiusSecretsStore SecretsStore { get; private set; }
2019-05-07 10:21:50 +02:00
ODB odb;
public ODBCollection<HotspotNetwork> hotspotNetworks { get; private set; }
2019-05-07 12:54:48 +02:00
public ODBCollection<RadiusSecretsStore> radiusSecretsCollection;
2019-05-07 10:21:50 +02:00
2019-05-10 13:27:06 +02:00
MappingBTree<HotspotNetwork, HotspotNetworkRuntime> hotspotRuntimes = new MappingBTree<HotspotNetwork, HotspotNetworkRuntime>((hr) => hr.HotspotNetwork);
public SessionManager SessionManager { get; private set; }
2019-05-07 10:21:50 +02:00
2019-05-07 10:21:25 +02:00
public HotspotManager()
{
2019-05-07 10:21:50 +02:00
odb = new ODB(BasePath);
hotspotNetworks = odb.GetCollection<HotspotNetwork>();
2019-05-07 12:54:48 +02:00
radiusSecretsCollection = odb.GetCollection<RadiusSecretsStore>();
2019-05-07 10:21:50 +02:00
2019-05-07 12:54:48 +02:00
SecretsStore = radiusSecretsCollection.FirstOrDefault();
if (SecretsStore == null)
SecretsStore = new RadiusSecretsStore();
2019-05-10 13:27:06 +02:00
SessionManager = new SessionManager(this);
2019-05-07 10:21:25 +02:00
}
2019-05-07 10:21:50 +02:00
2019-05-07 12:54:48 +02:00
public void SaveSecretsStore() => radiusSecretsCollection.Upsert(SecretsStore);
2019-05-10 13:27:06 +02:00
public void AddHotspotNetwork(HotspotNetwork hotspotNetwork)
{
if (!hotspotRuntimes.ContainsKey(hotspotNetwork))
hotspotRuntimes.Add(new HotspotNetworkRuntime(hotspotNetwork));
}
public void RemoveHotspotNetwork(HotspotNetwork hotspotNetwork)
2019-05-07 10:21:50 +02:00
{
2019-05-10 13:27:06 +02:00
if (hotspotRuntimes.ContainsKey(hotspotNetwork))
{
hotspotRuntimes.RemoveKey(hotspotNetwork);
}
}
public HotspotNetworkRuntime GetHotspotNetworkRuntime(HotspotNetwork hotspotNetwork)
{
return hotspotRuntimes[hotspotNetwork];
}
public HotspotNetworkRuntime GetHotspotNetworkRuntime(string networkName)
{
foreach (HotspotNetworkRuntime hotspotNetworkRuntime in hotspotRuntimes)
{
if (hotspotNetworkRuntime.HotspotNetwork.Name.Equals(networkName))
return hotspotNetworkRuntime;
}
throw new KeyNotFoundException();
}
2019-05-07 10:21:50 +02:00
2019-05-10 13:27:06 +02:00
public HotspotNetwork GetHotspotNetwork(String name)
{
foreach (HotspotNetworkRuntime hotspotNetworkRuntime in hotspotRuntimes)
{
if (hotspotNetworkRuntime.HotspotNetwork.Name.Equals(name))
return hotspotNetworkRuntime.HotspotNetwork;
}
throw new KeyNotFoundException();
2019-05-07 10:21:50 +02:00
}
2019-05-10 13:27:06 +02:00
2019-05-07 10:21:25 +02:00
}
}