Esempio n. 1
0
        public async void ConnectHandShake(UdpContext context)
        {
            var data = context.GetData <ConnectHandshakeDto>();
            var ep   = data.Ep;

            data.Info.OuterEP = PeerEP.ParsePeerEPFromIPEP(context.RemoteEndPoint);
            server.connectionDic[data.Info.OuterEP] = (ep, DateTime.UtcNow);
            await P2PServer.SendDataReliableAsync((int)CallMethods.PeerConnectionRequest, data.Info,
                                                  ep.ToIPEP(), server.ackTasks, server.msgs, server.timeoutData);

            _logger.LogInformation("send handshake data");
        }
Esempio n. 2
0
        public void HolePunchRequest(UdpContext context)
        {
            var reply = context.GetData <ConnectionReplyDto>() !;
            var ep    = reply.Ep;
            var rep   = PeerEP.ParsePeerEPFromIPEP(context.RemoteEndPoint);

            _logger.LogInformation("handshake reply get");
            var c = server.connectionDic.TryRemove(ep, out var t);

            if (c && t.Item1 == rep)
            {
                _ = P2PServer.SendDataReliableAsync((int)CallMethods.ConnectionRequestCallback, reply.Acc,
                                                    ep.ToIPEP(), server.ackTasks, server.msgs, server.timeoutData).AsTask();
                if (reply.Acc)
                {
                    _ = P2PServer.SendDataReliableAsync((int)CallMethods.StartPunching, "",
                                                        ep.ToIPEP(), server.ackTasks, server.msgs, server.timeoutData).AsTask();
                    _ = P2PServer.SendDataReliableAsync((int)CallMethods.StartPunching, "",
                                                        rep.ToIPEP(), server.ackTasks, server.msgs, server.timeoutData).AsTask();
                }
            }
        }