public async Task StartAsFirstNodeAsync(IEndPoint sourceEndPoint, IEndPoint publicEndPoint, IAsymmetricKey key, ISymmetricKey dummySymmetricKey, byte[] selfCustomData) { if (CurrentStatus != ClientStatus.NotConnected) { return; } if (selfCustomData.Length > 65000) //TODO { throw new DnmpException("Custom data length is larger than 65000 bytes"); } SelfCustomData = selfCustomData; SelfClient = new DnmpNode { Id = 0, EndPoint = publicEndPoint, CustomData = SelfCustomData }; Initialize(sourceEndPoint, key, dummySymmetricKey); CurrentStatus = ClientStatus.Connected; logger.Info($"Started as first node on {sourceEndPoint} [{publicEndPoint}]"); OnClientConnected?.Invoke(SelfClient.Id); OnConnected?.Invoke(); MessageInterface.Initialize(SelfClient.Id); await Task.Delay(0); }
public ConnectionNotificationMessage(byte[] data, IEndPointFactory endPointFactory) { var reader = new BigEndianBinaryReader(new MemoryStream(data)); Client = new DnmpNode { Id = reader.ReadUInt16(), EndPoint = endPointFactory.DeserializeEndPoint(reader.ReadBytes(reader.ReadUInt16())), CustomData = reader.ReadBytes(reader.ReadUInt16()) }; }
public void BroadcastClientConnect(DnmpNode client) { if (!running) { return; } webSocketServer.Broadcast(JsonConvert.SerializeObject(new { eventType = WebGuiEventType.ClientConnect, eventData = new { newClient = new ClientJsonData(client, mainClient) } })); }
public ClientJsonData(DnmpNode client, MainClient mainClient) { Id = client.Id; ParentId = client.ParentId; PublicIpPort = client.EndPoint.ToString(); InternalIp = mainClient.TapMessageInterface.GetIpFromId(client.Id).ToString(); InternalDomain = DomainNameUtil.GetDomain(client.GetDnmpNodeData().DomainName, mainClient.Config.TapConfig.DnsFormat); Flags = client.Flags; BytesReceived = client.BytesReceived; BytesSent = client.BytesSent; DataBytesReceived = client.DataBytesReceived; DataBytesSent = client.DataBytesSent; Ping = client.Flags.HasFlag(ClientFlags.SymmetricKeyExchangeDone) ? client.DirectPing : client.RedirectPing.Ping; }
public ConnectionNotificationMessage(DnmpNode client, IEndPointFactory endPointFactory) { Client = client; this.endPointFactory = endPointFactory; }
public static DnmpNodeData GetDnmpNodeData(this DnmpNode node) { return(JsonConvert.DeserializeObject <DnmpNodeData>(Encoding.UTF8.GetString(node.CustomData))); // TODO optimize }
internal void RemoveClient(DnmpNode client) { logger.Debug($"Removed client #{client.Id}"); ClientsById.TryRemove(client.Id, out _); OnClientDisconnected?.Invoke(client.Id); }
internal void AddClient(DnmpNode client) { logger.Debug($"Added client #{client.Id}"); ClientsById.TryAdd(client.Id, client); OnClientConnected?.Invoke(client.Id); }