Inheritance: Gwupe.Cloud.Messaging.API.Request
Example #1
0
        // Called by local application to initialise a p2p connection to a second party
        private ISocket InitP2PConnection(Attendance secondParty, String connectionId)
        {
            var initRq = new InitP2PConnectionRq { shortCode = secondParty.ActiveShortCode, connectionId = connectionId };
            TunnelEndpointContainer pendingTunnel;
            try
            {
                var response = GwupeClientAppContext.CurrentAppContext.ConnectionManager.Connection.Request<InitP2PConnectionRq, InitP2PConnectionRs>(initRq);
                // this will cause the server to initialise a tunnel endpoint and prepare it for connection
            #if DEBUG
                Logger.Debug("Got response from p2p connection request");
            #endif
                try
                {
                    pendingTunnel = GetPendingTunnel(response.uniqueId);

                    // setup my peers endpoints
                    var peer = GetPeerInfoFromResponse(response);
                    peer.FacilitatorRepeatedEndPoint = pendingTunnel.FacilitatorEndPoint;
                    pendingTunnel.TunnelEndpoint.Sync(peer, response.uniqueId, GwupeClientAppContext.CurrentAppContext.SettingsManager.SyncTypes);
                    Logger.Info("Successfully completed outgoing tunnel with " + secondParty.Party.Username + "-" + secondParty.ActiveShortCode + " [" + response.uniqueId + "]");
                }
                catch (Exception e)
                {
                    Logger.Error("Failed to sync with peer : " + e.Message, e);
                    ThreadPool.QueueUserWorkItem(m => GwupeClientAppContext.CurrentAppContext.SubmitFaultReport(
                        new FaultReport()
                        {
                            Subject = "Sync error",
                            UserReport = "INTERNAL : Failed to sync with peer : " + e.Message
                        }));
                    throw new Exception("Failed to sync with peer : " + e.Message, e);
                }
            }
            catch (Exception e)
            {
                Logger.Error("Failed to setup P2P Connection : " + e.Message, e);
                ThreadPool.QueueUserWorkItem(m => GwupeClientAppContext.CurrentAppContext.SubmitFaultReport(
                    new FaultReport()
                    {
                        Subject = "P2P setup error [" + connectionId + "]",
                        UserReport = "INTERNAL : Failed to setup p2p connection  [" + connectionId + "]: " + e.Message
                    }));
                throw new Exception("Failed to setup P2P Connection : " + e.Message, e);
            }
            return pendingTunnel.TunnelEndpoint;
        }