Example #1
0
        public MeshNode(MeshNodeType type, byte[] privateKey, SecureChannelCipherSuite supportedCiphers, ushort localServicePort, string profileDisplayName, string profileFolder, string downloadFolder, TorController torController)
        {
            _type                = type;
            _privateKey          = privateKey;
            _supportedCiphers    = supportedCiphers;
            _localServicePort    = localServicePort;
            _profileDateModified = DateTime.UtcNow;
            _profileDisplayName  = profileDisplayName;

            if (_type == MeshNodeType.Anonymous)
            {
                _enableUPnP = false;
                _allowInboundInvitations          = true;
                _allowOnlyLocalInboundInvitations = true;
            }
            else
            {
                _enableUPnP = true;
                _allowInboundInvitations          = true;
                _allowOnlyLocalInboundInvitations = false;
            }

            _profileFolder  = profileFolder;
            _downloadFolder = downloadFolder;

            GenerateNewUserId();

            //start connection manager
            _connectionManager = new ConnectionManager(this, torController);

            InitAnnounceTimer();
        }
Example #2
0
        private void InitMeshNode(BinaryReader bR, TorController torController)
        {
            switch (bR.ReadByte()) //version
            {
            case 1:
                _type             = (MeshNodeType)bR.ReadByte();
                _privateKey       = bR.ReadBuffer();
                _supportedCiphers = (SecureChannelCipherSuite)bR.ReadByte();

                //
                _userId = new BinaryNumber(bR.BaseStream);

                //
                _localServicePort = bR.ReadUInt16();
                _downloadFolder   = bR.ReadShortString();

                //
                _profileDateModified  = bR.ReadDate();
                _profileDisplayName   = bR.ReadShortString();
                _profileStatus        = (MeshProfileStatus)bR.ReadByte();
                _profileStatusMessage = bR.ReadShortString();

                //
                _profileImageDateModified = bR.ReadDate();
                _profileDisplayImage      = bR.ReadBuffer();

                //
                _ipv4BootstrapDhtNodes = new EndPoint[bR.ReadInt32()];
                for (int i = 0; i < _ipv4BootstrapDhtNodes.Length; i++)
                {
                    _ipv4BootstrapDhtNodes[i] = EndPointExtension.Parse(bR);
                }

                _ipv6BootstrapDhtNodes = new EndPoint[bR.ReadInt32()];
                for (int i = 0; i < _ipv6BootstrapDhtNodes.Length; i++)
                {
                    _ipv6BootstrapDhtNodes[i] = EndPointExtension.Parse(bR);
                }

                _torBootstrapDhtNodes = new EndPoint[bR.ReadInt32()];
                for (int i = 0; i < _torBootstrapDhtNodes.Length; i++)
                {
                    _torBootstrapDhtNodes[i] = EndPointExtension.Parse(bR);
                }

                //
                _enableUPnP = bR.ReadBoolean();
                _allowInboundInvitations          = bR.ReadBoolean();
                _allowOnlyLocalInboundInvitations = bR.ReadBoolean();

                //
                if (bR.ReadBoolean())
                {
                    _proxy = new NetProxy((NetProxyType)bR.ReadByte(), bR.ReadShortString(), bR.ReadUInt16(), (bR.ReadBoolean() ? new NetworkCredential(bR.ReadShortString(), bR.ReadShortString()) : null));
                }

                //
                _appData = bR.ReadBuffer();

                //start connection manager
                _connectionManager = new ConnectionManager(this, torController);

                //
                int networkCount = bR.ReadInt32();

                for (int i = 0; i < networkCount; i++)
                {
                    MeshNetwork network = new MeshNetwork(_connectionManager, bR);
                    _networks.Add(network.NetworkId, network);
                }

                InitAnnounceTimer();
                break;

            default:
                throw new InvalidDataException("MeshNode format version not supported.");
            }
        }