/*public void SendUnreliable(RudpAddress address, uint service, int type, G2Packet packet) * { * // insecure, rudp provides this same method which is more secure, if a rudp connection is already established * * RudpPacket wrap = CreateRudpPacket(address.Address, service, type, packet, false); * * int sentBytes = LightClient.SendtoAddress(Core.Network, address, wrap); * * Core.ServiceBandwidth[service].OutPerSec += sentBytes; * }*/ public void ReceivePacket(G2ReceivedPacket raw, RudpPacket packet) { DhtClient client = new DhtClient(packet.SenderID, packet.SenderClient); if (!Clients.ContainsKey(client.RoutingID)) { Clients[client.RoutingID] = new LightClient(client); } LightClient light = Clients[client.RoutingID]; light.LastSeen = Core.TimeNow; // either direct, or node's proxy light.AddAddress(Core, new RudpAddress(raw.Source), true); if (raw.ReceivedTcp) // add this second so sending ack through tcp proxy is perferred { light.AddAddress(Core, new RudpAddress(raw.Source, raw.Tcp), true); } if (packet.PacketType == RudpPacketType.LightAck) { ReceiveAck(raw, light, packet); } else if (packet.PacketType == RudpPacketType.Light) { RudpLight info = new RudpLight(packet.Payload); if (Core.ServiceBandwidth.ContainsKey(info.Service)) { Core.ServiceBandwidth[info.Service].InPerSec += raw.Root.Data.Length; } if (Data.Contains(info.Service, info.Type)) { Data[info.Service, info.Type].Invoke(client, info.Data); } if (packet.Sequence == 1) // reliable packet { SendAck(light, packet, info.Service); } } }
public void Update(LocationData location) { DhtClient client = new DhtClient(location.Source); if (!Clients.ContainsKey(client.RoutingID)) { Clients[client.RoutingID] = new LightClient(client); } LightClient light = Clients[client.RoutingID]; light.AddAddress(Core, new DhtAddress(location.IP, location.Source), false); foreach (DhtAddress address in location.Proxies) { light.AddAddress(Core, address, false); } foreach (DhtAddress server in location.TunnelServers) { light.AddAddress(Core, new DhtContact(location.Source, location.IP, location.TunnelClient, server), false); } }