Exemple #1
0
        public void UpdateLatency(string address, double rtt)
        {
            double moving_rtt;

            if (_latencies.TryGetValue(address, out moving_rtt))
            {
                double new_rtt = _exp_factor * (moving_rtt - rtt) + rtt;
                _latencies = _latencies.InsertIntoNew(address, new_rtt);
            }
            else
            {
                _latencies = _latencies.InsertIntoNew(address, rtt);
            }
        }
Exemple #2
0
        public void HandleSvpnMsg(Element msg, JID from)
        {
            SvpnMsg request = msg as SvpnMsg;

            if (request == null)
            {
                return;
            }

            string[] parts = request.Data.Split(DELIM);
            string   jid   = from.User + "@" + from.Server;

            if (!_fingerprints.ContainsKey(parts[1]))
            {
                _fingerprints = _fingerprints.InsertIntoNew(parts[1], parts[0]);
            }

            if (!_addresses.ContainsKey(jid))
            {
                _addresses = _addresses.InsertIntoNew(parts[1], jid);
            }

            if (parts[2] == PacketTypes.Request.ToString() && _xmpp.JID != from)
            {
                string data = _data + DELIM + PacketTypes.Reply.ToString();
                _xmpp.SendTo(new SvpnMsg(_doc, data), from);
            }
        }
        public DnsMapping AddDnsMapping(string alias, string ip, string source)
        {
            string     address = GetAddress(ip);
            DnsMapping mapping = new DnsMapping(alias, address, ip, source);

            _mappings = _mappings.InsertIntoNew(mapping.Alias, mapping);
            return(mapping);
        }
        public string AddTmpMapping(DnsMapping mapping)
        {
            string id = mapping.ToIDString();

            if (!_tmappings.ContainsKey(id))
            {
                _tmappings = _tmappings.InsertIntoNew(id, mapping);
            }
            return(_node.Address);
        }
        protected void SendRpcMessage(Address addr, string method,
                                      string query, bool secure)
        {
            DateTime sent = DateTime.Now;

#if !SVPN_NUNIT
            string  meth_call = RPCID + "." + method;
            Channel q         = new Channel();
            q.CloseAfterEnqueue();
            q.CloseEvent += delegate(object obj, EventArgs eargs) {
                try {
                    RpcResult res    = (RpcResult)q.Dequeue();
                    string    result = (string)res.Result;

                    if (method == "Ping")
                    {
                        DateTime recv = DateTime.Now;
                        _times = _times.InsertIntoNew(result, recv);
                        TimeSpan rtt = recv - sent;
                        _ssm.UpdateLatency(result, rtt.TotalMilliseconds);
                    }

                    ProtocolLog.WriteIf(SocialLog.SVPNLog,
                                        String.Format("RPC {0} {1} {2}", addr.ToString(), method,
                                                      query));
                } catch (Exception e) {
                    ProtocolLog.WriteIf(SocialLog.SVPNLog, e.ToString());
                }
            };

            ISender sender;
            if (!secure)
            {
                sender = new AHExactSender(_node.Node, addr);
            }
            else
            {
                sender = _node.Bso.GetSecureSender(addr);
            }
            _rpc.Invoke(sender, q, meth_call, _node.Address, query);
#endif
        }
Exemple #6
0
        public SocialUser AddFriend(string address, string cert, string uid,
                                    string ip)
        {
            if (_friends.ContainsKey(address))
            {
                throw new Exception("Address already exists");
            }

            Address    addr   = AddressParser.Parse(address);
            string     new_ip = _marad.AddIPMapping(ip, addr);
            SocialUser user   = new SocialUser(cert, new_ip, null);

            Bso.CertificateHandler.AddCACertificate(user.X509);
            _mco.Set(addr);
            _friends = _friends.InsertIntoNew(address, user);

            return(user);
        }
Exemple #7
0
        protected void Retreive()
        {
            string url    = URL + "/";
            string result = SocialUtils.Request(url);

            int counter = 0;

            string[] lines = result.Split('\n');
            foreach (string line in lines)
            {
                if (line.Length < 10)
                {
                    continue;
                }
                string[] parts = line.Split(' ');
                _fingerprints = _fingerprints.InsertIntoNew(parts[0], parts[1]);
                _addresses    = _addresses.InsertIntoNew(parts[0], parts[2]);
                counter++;
            }

            _message = " >> Found " + counter + " test server(s)";
        }
        public void ProcessHandler(Object obj, EventArgs eargs)
        {
            Dictionary <string, string> request = (Dictionary <string, string>)obj;
            string method = String.Empty;

            if (request.ContainsKey("m"))
            {
                method = request["m"];
                ProtocolLog.WriteIf(SocialLog.SVPNLog,
                                    String.Format("SVPN Method Call {0}", method));
            }

            if (_node.LocalUser == null && (method == String.Empty ||
                                            method != "setuid"))
            {
                if (method != "login")
                {
                    throw new Exception("Uid not set");
                }
            }

            if (request.ContainsKey("a") && !request["a"].StartsWith("brunet"))
            {
                request["a"] = "brunet:node:" + request["a"];
            }
            switch (method)
            {
            case "add":
                AddToPending(request["a"]);
                if (request.ContainsKey("f"))
                {
                    _fprs = _fprs.InsertIntoNew(request["a"], request["f"]);
                }
                break;

            case "block":
                Block(request["a"]);
                break;

            case "unblock":
                Unblock(request["a"]);
                break;

            case "del":
                _node.RemoveFriend(request["a"]);
                break;

            case "login":
                Login(request["n"], request["u"], request["p"]);
                break;

            case "logout":
                Logout(request["n"]);
                break;

            case "setuid":
                _node.SetUid(request["u"], request["p"]);
                break;

            case "shutdown":
                _node.Close();
                break;

            case "autofriend":
                _auto_allow = (_auto_allow ^ true);
                break;

            case "sdns.search":
                _sdm.SearchFriends(request["q"], this);
                request["response"] = _sdm.GetState(request["q"]);
                return;

            case "sdns.add":
                _sdm.AddDnsMapping(request["n"], request["i"]);
                request["response"] = _sdm.GetState(request["q"]);
                return;

            case "sdns.del":
                _sdm.DeleteDnsMapping(request["n"]);
                request["response"] = _sdm.GetState(request["q"]);
                return;

            case "sdns.state":
                request["response"] = _sdm.GetState(request["q"]);
                return;

            case "nat":
                request["response"] = _node.GetNatType();
                return;

            default:
                break;
            }
            request["response"] = GetState(true);
        }
 public void Register(string name, ISocialNetwork network)
 {
     _networks = _networks.InsertIntoNew(name, network);
 }