示例#1
0
        /// <summary>
        /// Peer will destroy all connections. All known peers will be cleared.
        /// I have been thinking about making this method public however I don't want users
        /// to use it to temporary stop listening. It should be used to terminate all connections
        /// at the end of an application.
        /// </summary>
        /// <returns></returns>
        private void CloseConnection()
        {
            if (listener == null)
            {
                listener.Dispose();
                listener = null;
            }

            KnownPeers.Clear();
        }
示例#2
0
        /// <summary>
        /// Turns the current session into a serialized byte array
        /// </summary>
        public byte[] Serialize()
        {
            using var memory = new MemoryStream();
            using var writer = new BinaryWriter(memory);

            if (Helper == null)
            {
                BoolUtil.Serialize(false, writer);
            }
            else
            {
                BoolUtil.Serialize(true, writer);
                BytesUtil.Serialize(Helper.Serialize(), writer);
            }

            if (TLUser == null)
            {
                BoolUtil.Serialize(false, writer);
            }
            else
            {
                BoolUtil.Serialize(true, writer);
                TLUser.Serialize(writer);
            }

            IntegerUtil.Serialize(SessionExpires, writer);

            if (DataCenter == null)
            {
                BoolUtil.Serialize(false, writer);
            }
            else
            {
                BoolUtil.Serialize(true, writer);
                BytesUtil.Serialize(DataCenter.Serialize(), writer);
            }

            BytesUtil.Serialize(KnownPeers.Serialize(), writer);

            return(memory.ToArray());
        }
示例#3
0
 /// <summary>
 /// Clears the data that pertains to a given session
 /// </summary>
 public void Reset()
 {
     TLUser = null;
     KnownPeers.Clear();
     Save();
 }