Esempio n. 1
0
        public void Reset()
        {
            NodeId = DHTId.CreateRandom();

            UserName = Environment.UserName;

            Country = RegionInfo.CurrentRegion.ThreeLetterISORegionName;
            //return RegionInfo.CurrentRegion.DisplayName;

            TimeZone localZone = System.TimeZone.CurrentTimeZone;
            var      result    = localZone.StandardName;
            var      offset    = localZone.GetUtcOffset(DateTime.Now);
            var      offsetStr = (offset.TotalMilliseconds < 0) ? offset.ToString() : "+" + offset.ToString();

            TimeZone = string.Format("{0} (UTC{1})", result, offsetStr);

            string langs = INVISIBLE_PROFILE_VALUE;

            /*foreach (InputLanguage c in InputLanguage.InstalledInputLanguages) {
             *  langs += (langs.Length != 0) ? ", " : "";
             *  langs += (c.Culture.ThreeLetterISOLanguageName);
             * }*/
            Languages = langs;

            Email = INVISIBLE_PROFILE_VALUE;

            PublicKey = string.Empty;
        }
Esempio n. 2
0
        public void LoadProfile(UserProfile profile)
        {
            bool initialized = GetParameterBool("profile_initialized");

            if (initialized)
            {
                profile.NodeId = DHTId.Parse(GetParameterValue("user_node_id"));

                profile.UserName  = GetParameterValue("user_name");
                profile.Country   = GetParameterValue("user_country");
                profile.TimeZone  = GetParameterValue("user_timezone");
                profile.Languages = GetParameterValue("user_languages");
                profile.Email     = GetParameterValue("user_email");

                profile.IsCountryVisible   = GetParameterBool("user_country_visible");
                profile.IsTimeZoneVisible  = GetParameterBool("user_timezone_visible");
                profile.IsLanguagesVisible = GetParameterBool("user_languages_visible");
                profile.IsEmailVisible     = GetParameterBool("user_email_visible");

                profile.PasswordHash = GetParameterValue("user_password");
                profile.PublicKey    = GetParameterValue("user_public_key");
                profile.PrivateKey   = GetParameterValue("user_private_key");
            }
            else
            {
                profile.Reset();
                SaveProfile(profile);
            }
        }
        private void InitializePeers()
        {
            fShowConnectionInfo = fDatabase.GetParameterBool("show_connection_info");

            fLocalPeer          = AddPeer(fPublicEndPoint, fProfile);
            fLocalPeer.State    = PeerState.Unknown;
            fLocalPeer.Presence = fDatabase.LoadPresence();

            var dbPeers = fDatabase.LoadPeers();

            foreach (var rp in dbPeers)
            {
                var remoteProfile = new PeerProfile();
                remoteProfile.NodeId    = DHTId.Parse(rp.node_id);
                remoteProfile.UserName  = rp.user_name;
                remoteProfile.Country   = rp.country;
                remoteProfile.Languages = rp.langs;
                remoteProfile.TimeZone  = rp.timezone;
                remoteProfile.Email     = rp.email;
                remoteProfile.PublicKey = rp.public_key;

                var remotePeer = AddPeer(Utilities.ParseIPEndPoint(rp.last_endpoint), remoteProfile);
                remotePeer.IsLocal  = false;
                remotePeer.State    = PeerState.Unknown;
                remotePeer.Presence = PresenceStatus.Offline;
            }
        }
Esempio n. 4
0
        public void Test_CreateGetPeerInfoQuery()
        {
            var tid    = DHTTransactions.GetNextId();
            var nodeId = DHTId.CreateRandom();
            var msg    = ProtocolHelper.CreateGetPeerInfoQuery(tid, nodeId);

            Assert.IsNotNull(msg);
            // TODO: test contents
        }
Esempio n. 5
0
        public void Test_CreateChatMessage()
        {
            var tid    = DHTTransactions.GetNextId();
            var nodeId = DHTId.CreateRandom();
            var msg    = ProtocolHelper.CreateChatMessage(tid, nodeId, "test", false, 0);

            Assert.IsNotNull(msg);
            // TODO: test contents
        }
Esempio n. 6
0
        public void Test_CreateHandshakeResponse()
        {
            var tid    = DHTTransactions.GetNextId();
            var nodeId = DHTId.CreateRandom();
            var msg    = ProtocolHelper.CreateHandshakeResponse(tid, nodeId, PresenceStatus.Online);

            Assert.IsNotNull(msg);
            // TODO: test contents
        }
Esempio n. 7
0
        public void UpdateMessageDelivered(DHTId receiverId, long timestamp)
        {
            if (!IsConnected)
            {
                throw new DatabaseException("Database disconnected");
            }

            fConnection.Execute(string.Format("update Messages set flags = 1 where (receiver = '{0}' and timestamp = {1})", receiverId, timestamp));
        }
 private Peer AddPeer(string nodeId)
 {
     lock (fPeers) {
         Peer peer = new Peer(new IPEndPoint(DHTClient.IPAnyAddress, 0), new PeerProfile());
         peer.ID = DHTId.Parse(nodeId);
         fPeers.Add(peer);
         return(peer);
     }
 }
Esempio n. 9
0
        public void Test_CreateGetPeerInfoResponse()
        {
            var peerInfo = new UserProfile();

            peerInfo.Reset();

            var tid    = DHTTransactions.GetNextId();
            var nodeId = DHTId.CreateRandom();
            var msg    = ProtocolHelper.CreateGetPeerInfoResponse(tid, nodeId, peerInfo);

            Assert.IsNotNull(msg);
            // TODO: test contents
        }
        public static BDictionary CreateGetPeerInfoQuery(BString transactionID, DHTId nodeId)
        {
            var data = new BDictionary();

            data.Add("t", transactionID);
            data.Add("y", "q");
            data.Add("q", "get_peer_info");

            var args = new BDictionary();

            args.Add("id", nodeId.ToBencodedString());
            data.Add("a", args);

            return(data);
        }
        public static BDictionary CreateGetPeerInfoResponse(BString transactionID, DHTId nodeId, UserProfile peerProfile)
        {
            var data = new BDictionary();

            data.Add("t", transactionID);
            data.Add("y", "r");

            var r = new BDictionary();

            r.Add("q", "get_peer_info");
            r.Add("id", nodeId.ToBencodedString());
            peerProfile.Save(r);
            data.Add("r", r);

            return(data);
        }
        public static BDictionary CreateChatResponse(BString transactionID, DHTId nodeId, long timestamp)
        {
            var data = new BDictionary();

            data.Add("t", transactionID);
            data.Add("y", "r");

            var r = new BDictionary();

            r.Add("q", MSG_SIGN_CHAT);
            r.Add("id", nodeId.ToBencodedString());
            r.Add("ts", timestamp);
            data.Add("r", r);

            return(data);
        }
        public static BDictionary CreateHandshakeQuery(BString transactionID, DHTId nodeId)
        {
            var data = new BDictionary();

            data.Add("t", transactionID);
            data.Add("y", "q");
            data.Add("q", "handshake");

            var args = new BDictionary();

            args.Add("id", nodeId.ToBencodedString());
            args.Add("app", "GEDKeeper Communicator");
            args.Add("ver", "2.14.0");
            data.Add("a", args);

            return(data);
        }
        public static BDictionary CreateHandshakeResponse(BString transactionID, DHTId nodeId, PresenceStatus presence)
        {
            var data = new BDictionary();

            data.Add("t", transactionID);
            data.Add("y", "r");

            var r = new BDictionary();

            r.Add("q", "handshake");
            r.Add("id", nodeId.ToBencodedString());
            r.Add("app", "GEDKeeper Communicator");
            r.Add("ver", "2.14.0");
            r.Add("presence", new BNumber((int)presence));
            data.Add("r", r);

            return(data);
        }
Esempio n. 15
0
        public IEnumerable <DHTNode> LoadNodes()
        {
            var result = new List <DHTNode>();

            string query   = string.Format("select * from DHTNodes");
            var    dbNodes = fConnection.Query <DBNode>(query);

            if (dbNodes != null)
            {
                foreach (var dbn in dbNodes)
                {
                    var nodeId   = DHTId.Parse(dbn.node_id);
                    var endPoint = Utilities.ParseIPEndPoint(dbn.endpoint);
                    result.Add(new DHTNode(nodeId, endPoint));
                }
            }

            return(result);
        }
        public static BDictionary CreateChatMessage(BString transactionID, DHTId nodeId, string message, bool encrypted, long timestamp)
        {
            var data = new BDictionary();

            data.Add("t", transactionID);
            data.Add("y", "q");
            data.Add("q", MSG_SIGN_CHAT);

            var args = new BDictionary();

            args.Add("id", nodeId.ToBencodedString());
            args.Add("msg", message);
            args.Add("enc", Convert.ToInt32(encrypted));
            args.Add("ts", timestamp);
            data.Add("a", args);

            data.Add("handshake", "gkn"); // ???

            return(data);
        }