forked from tmoonlight/NSmartProxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerModels.cs
More file actions
75 lines (63 loc) · 1.74 KB
/
ServerModels.cs
File metadata and controls
75 lines (63 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using NSmartProxy.Infrastructure;
namespace NSmartProxy
{
public struct ClientIDAppID
{
public int ClientID;
public int AppID;
}
/// <summary>
/// nspclient集合 clientid->NSPClient
/// </summary>
public class NSPClientCollection:IEnumerable<NSPClient>
{
private ConcurrentDictionary<int, NSPClient> ClientMap;
public NSPClient this[int index]
{
get => ClientMap[index];
set => ClientMap[index] = value;
}
public NSPClientCollection()
{
ClientMap = new ConcurrentDictionary<int, NSPClient>();
}
public bool ContainsKey(int key)
{
return ClientMap.ContainsKey(key);
}
public void RegisterNewClient(int key)
{
ClientMap.TryAdd(key,new NSPClient()
{
ClientID = key,
LastUpdateTime = DateTime.Now
});
}
public void UnRegisterClient(int key)
{
//关闭所有连接
//int closedClients = ClientMap[key].Close();
this.ClientMap.TryRemove(key,out _);
//停止端口侦听
//return closedClients;
}
public IEnumerator<NSPClient> GetEnumerator()
{
return ClientMap.Values.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
public class AppChangedEventArgs : EventArgs
{
public NSPApp App;
}
}