public async UniTask CreateKey(byte[] buffer, UdpClient udpSocket ,SocketUdp socketUdp) { var publicKey = RSAPublicKey.Deserialize(buffer); RSA = new RSA(); var key = RSA.CreateKey(publicKey.Modules, publicKey.Exponent); AESKey = key.aeskey; Command obj = new Command { P2PEventType = CommandType.AcceptKey, Value = key.encrypted, }; var array = new Command[1]; array[0] = obj; var l2 = new UdpPacketL2 { Commands = array, PacketNumber = 0, ACKNumber = 0, }.Serialize(); var buf = new UdpPacket { PeerID = UniP2PManager.MyPeerID, UdpPacketL2 = l2, UdpPacketL2IV = null }.Serialize(); await udpSocket.SendAsync(buf, buf.Length, Peer.IPEndPoint); PacketCapture.Write(Peer.IPEndPoint.ToString(), buf.Length, "CreateKey"); State = UdpConnectionState.Connected; Peer.State = PeerState.Connected; InitHeartBeatAsync(socketUdp); }
public void AcceptKey(byte[] buffer, SocketUdp socketUdp) { AESKey = RSA.AcceptKey(buffer); State = UdpConnectionState.Connected; Peer.State = PeerState.Connected; InitHeartBeatAsync(socketUdp); }
void PeerReload() { if (SocketUdp.GetUdpConnectionsCount() != 0) { udpInfoTreeView.Reload(); } Repaint(); }
public async UniTask HeartBeatAsync(SocketUdp socket) { try { while (State == UdpConnectionState.Connected) { await socket.SendHeartBeatAsync(this); await UniTask.Delay(1000); } } catch (Exception ex) { Debug.Debugger.Warning(ex); await HeartBeatAsync(socket); } }
void OnGUI() { RenderHeadPanel(); if (EnableAutoReload && SocketUdp.GetUdpConnectionsCount() != c_count) { PeerReload(); c_count = SocketUdp.GetUdpConnectionsCount(); } SplitterGUILayout.BeginVerticalSplit(this.splitterState, EmptyLayoutOption); { RenderTable(); } SplitterGUILayout.EndVerticalSplit(); }
public async void InitHeartBeatAsync(SocketUdp socket) { await UniTask.WhenAll(HeartBeatAsync(socket), CheckHeartBeatAsync()); }