public void ConnectToOperator(MessageTransfer.EndPoint serverEndPoint) { messageClientToServer.Connect(serverEndPoint.ToIPEndPoint()); var p2pRequest = new P2PRequest { UserEmail = this.Email, UserID = this.ID, UserName = this.Name }; messageClientToServer.SendMessage(p2pRequest); }
private void HandleUDPP2PRequest(PacketHeader header, Connection connection, P2PRequest p2pRequest) { if (connection == null || p2pRequest == null) { return; } var sourceClient = _clientSessionList.FirstOrDefault(cs => cs.Guid == p2pRequest.SourceGuid); if (sourceClient == null) { return; } var targetClient = _clientSessionList.FirstOrDefault(cs => cs.Guid == p2pRequest.TargetGuid); if (targetClient == null) { return; } //udp ip/port var sourceUDPIPPort = (IPEndPoint)connection.ConnectionInfo.RemoteEndPoint; //tcp ip/port var sourceTCPIPPort = (IPEndPoint)sourceClient.Connection.ConnectionInfo.RemoteEndPoint; var targetTCPIPPort = (IPEndPoint)targetClient.Connection.ConnectionInfo.RemoteEndPoint; ConsoleHelper.Info(string.Format("[ {0} ] {1}({2}:{3}) request {4}({5}:{6}) P2P to {7}:{8}", connection.ConnectionInfo.ConnectionType, sourceClient.Name, sourceTCPIPPort.Address, sourceTCPIPPort.Port, targetClient.Name, targetTCPIPPort.Address, targetTCPIPPort.Port, sourceUDPIPPort.Address, sourceUDPIPPort.Port)); targetClient.Connection.SendObject <P2PClient>(PacketType.REQ_UDPP2PRequest, new P2PClient { GUID = p2pRequest.SourceGuid, IP = sourceUDPIPPort.Address.ToString(), Port = sourceUDPIPPort.Port }); }
/// <summary> /// Diese Methode dient zur Anbindung der P2P Topology an die Hierarchische. /// Es wird ein entsprechendes Paket in das hierarchische Netz gesendet. /// </summary> /// <param name="p2pRequest"></param> /// <param name="username"></param> /// <param name="kaEvent"></param> /// <param name="writeResult">übergebe die Methode writeResult</param> void ConnectP2P(P2PRequest p2pRequest, string username, KaEvent kaEvent, Action <Request, string> writeResult) { //P2P Teil P2PPackage p2p = new P2PPackage(username, kaEvent) { P2Prequest = p2pRequest }; //Sende Teil Package sendPackage = new Package(p2p); Package recievePackage; recievePackage = Send(sendPackage, KnownServers.GetRandomWellKnownPeer()); if (recievePackage != null) { switch (recievePackage.p2p.P2PAnswer) { case P2PAnswer.Success: writeResult(Request.Success, InviteSuccess); break; case P2PAnswer.Failure: writeResult(Request.Failure, InviteFail); break; default: writeResult(Request.Failure, InviteFail); break; } } else { writeResult(Request.Error, Error); } }
private void HandleP2PEstablished(PacketHeader header, Connection connection, P2PRequest p2pRequest) { if (connection == null || p2pRequest == null) { return; } var sourceClient = _clientSessionList.FirstOrDefault(cs => cs.Guid == p2pRequest.SourceGuid); if (sourceClient == null) { return; } var targetClient = _clientSessionList.FirstOrDefault(cs => cs.Guid == p2pRequest.TargetGuid); if (targetClient == null) { return; } ConsoleHelper.Info(string.Format("[ TCP ] {0} Established P2P connection with {1}", sourceClient.Name, targetClient.Name)); }