コード例 #1
0
 /// <summary>
 /// Frees the resources used by the object
 /// </summary>
 /// <param name="disposing">The parameter tells if the Dispose is called directly</param>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (this.chan != null)
         {
             this.Leave();
         }
     }
     this.chan = null;
 }
コード例 #2
0
        /// <summary>
        /// Leaves the PeerChannel.
        /// </summary>
        public void Leave()
        {
            if (this.State == ScallopNetworkState.Online)
            {
                this.chan.PCLeave(this.id);
            }

            try
            {
                this.chan.Close();
                this.chan = null;
                this.factory.Close();
                this.factory    = null;
                this.registered = false;
                doStateChanged(this, new ScallopNetworkStatusChangedEventArgs(this.myState, ScallopNetworkState.Offline));
            }
            catch
            { }
        }
コード例 #3
0
        /// <summary>
        /// 
        /// </summary>
        private void registerPeerChannel(string id)
        {
            XmlDictionaryReaderQuotas quotas = new XmlDictionaryReaderQuotas();
             quotas.MaxArrayLength = int.MaxValue;
             quotas.MaxBytesPerRead = int.MaxValue;
             quotas.MaxDepth = int.MaxValue;
             quotas.MaxNameTableCharCount = int.MaxValue;
             quotas.MaxStringContentLength = int.MaxValue;

             NetPeerTcpBinding myBinding = new NetPeerTcpBinding();
             myBinding.ReaderQuotas = quotas;
             myBinding.Resolver.Mode = System.ServiceModel.PeerResolvers.PeerResolverMode.Pnrp;

             if (parameters.UseTLS)
             {
            myBinding.Security.Mode = SecurityMode.Transport;
            myBinding.Security.Transport.CredentialType = PeerTransportCredentialType.Password;
             }
             else
             {
            myBinding.Security.Mode = SecurityMode.None;
             }

             // if the listening address is specified, use it
             if (parameters.Ip != null)
             {
            this.doInfo(this, new ScallopInfoEventArgs("Ignored listening address"));
            /*
            this.doInfo(this, new ScallopInfoEventArgs("Listening on ip " + parameters.Ip.ToString()));
            myBinding.ListenIPAddress = parameters.Ip;
            */
             }

             EndpointAddress myAddress = new EndpointAddress("net.p2p://Scallop_" + this.Version + "_" + parameters.NetworkName + "/");

             this.factory = new DuplexChannelFactory<IPeerChannelChannel>(new InstanceContext(this), myBinding, myAddress);
             this.factory.Faulted += this.factory_faulted;
             this.factory.Closed += this.factory_faulted;

             if (parameters.UseTLS)
            this.factory.Credentials.Peer.MeshPassword = parameters.TLSPassword;

             this.chan = factory.CreateChannel();

             ScallopMessageFilter msgFilter = new ScallopMessageFilter(id);
             peer = chan.GetProperty<PeerNode>();
             peer.Offline += new EventHandler(peer_Offline);
             peer.Online += new EventHandler(peer_Online);
             peer.MessagePropagationFilter = msgFilter;

             this.chan.Open();

             this.chan.PCJoin(this.id);
             this.registered = true;

             this.id = id;

             //if(peer.IsOnline)
             //   this.doStateChanged(this, new ScallopNetworkStatusChangedEventArgs(ScallopNetworkState.Online, null, "Online"));
        }
コード例 #4
0
 /// <summary>
 /// Frees the resources used by the object
 /// </summary>
 /// <param name="disposing">The parameter tells if the Dispose is called directly</param>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
      {
     if (this.chan != null)
        this.Leave();
      }
      this.chan = null;
 }
コード例 #5
0
        /// <summary>
        /// Leaves the PeerChannel.
        /// </summary>
        public void Leave()
        {
            if (this.State == ScallopNetworkState.Online)
            this.chan.PCLeave(this.id);

             try
             {
            this.chan.Close();
            this.chan = null;
            this.factory.Close();
            this.factory = null;
            this.registered = false;
            doStateChanged(this, new ScallopNetworkStatusChangedEventArgs(this.myState, ScallopNetworkState.Offline));
             }
             catch
             { }
        }
コード例 #6
0
        /// <summary>
        ///
        /// </summary>
        private void registerPeerChannel(string id)
        {
            XmlDictionaryReaderQuotas quotas = new XmlDictionaryReaderQuotas();

            quotas.MaxArrayLength         = int.MaxValue;
            quotas.MaxBytesPerRead        = int.MaxValue;
            quotas.MaxDepth               = int.MaxValue;
            quotas.MaxNameTableCharCount  = int.MaxValue;
            quotas.MaxStringContentLength = int.MaxValue;

            NetPeerTcpBinding myBinding = new NetPeerTcpBinding();

            myBinding.ReaderQuotas  = quotas;
            myBinding.Resolver.Mode = System.ServiceModel.PeerResolvers.PeerResolverMode.Pnrp;

            if (parameters.UseTLS)
            {
                myBinding.Security.Mode = SecurityMode.Transport;
                myBinding.Security.Transport.CredentialType = PeerTransportCredentialType.Password;
            }
            else
            {
                myBinding.Security.Mode = SecurityMode.None;
            }

            // if the listening address is specified, use it
            if (parameters.Ip != null)
            {
                this.doInfo(this, new ScallopInfoEventArgs("Ignored listening address"));

                /*
                 * this.doInfo(this, new ScallopInfoEventArgs("Listening on ip " + parameters.Ip.ToString()));
                 * myBinding.ListenIPAddress = parameters.Ip;
                 */
            }

            EndpointAddress myAddress = new EndpointAddress("net.p2p://Scallop_" + this.Version + "_" + parameters.NetworkName + "/");

            this.factory          = new DuplexChannelFactory <IPeerChannelChannel>(new InstanceContext(this), myBinding, myAddress);
            this.factory.Faulted += this.factory_faulted;
            this.factory.Closed  += this.factory_faulted;

            if (parameters.UseTLS)
            {
                this.factory.Credentials.Peer.MeshPassword = parameters.TLSPassword;
            }

            this.chan = factory.CreateChannel();

            ScallopMessageFilter msgFilter = new ScallopMessageFilter(id);

            peer          = chan.GetProperty <PeerNode>();
            peer.Offline += new EventHandler(peer_Offline);
            peer.Online  += new EventHandler(peer_Online);
            peer.MessagePropagationFilter = msgFilter;

            this.chan.Open();

            this.chan.PCJoin(this.id);
            this.registered = true;

            this.id = id;

            //if(peer.IsOnline)
            //   this.doStateChanged(this, new ScallopNetworkStatusChangedEventArgs(ScallopNetworkState.Online, null, "Online"));
        }