Ejemplo n.º 1
0
    protected SocialUser AddFriend(string certb64, string uid, string ip) {
      bool new_friend = IsNewFriend(uid);
      SocialUser user = new SocialUser();
      user.Certificate = certb64;
      user.Status = StatusTypes.Offline.ToString();
      user.Time = String.Empty;

      if (user.Uid.ToLower() != uid.ToLower()) {
        throw new Exception("Uids do not match");
      }

      foreach (SocialUser tmp_user in GetFriends()) {
        if (tmp_user.Address == user.Address) {
          throw new Exception("Address already exists");
        }
      }

      if (_friends.ContainsKey(user.Alias)) {
        RemoveFriend(user.Alias);
      }

      Address addr = AddressParser.Parse(user.Address);
      _bso.CertificateHandler.AddCACertificate(user.GetCert().X509);
      AppNode.Node.ManagedCO.AddAddress(addr);
      user.IP = _marad.AddIPMapping(ip, addr);
      _marad.AddDnsMapping(user.Alias, user.IP, true);
      user.Access = AccessTypes.Allow.ToString();

      lock (_sync) {
        _friends.Add(user.Alias, user);
      }
      // Check global block option and block if necessary
      if((new_friend && _global_block.Value) || _bfriends.Contains(uid)) {
        Block(uid);
      }
      GetState(true);
      return user;
    }
Ejemplo n.º 2
0
 public SocialNode(NodeConfig brunetConfig, IpopConfig ipopConfig,
                   string certificate) : base(brunetConfig, ipopConfig) {
   _friends = new Dictionary<string, SocialUser>();
   _bfriends = new List<string>();
   _sync = new object();
   _status = StatusTypes.Offline.ToString();
   _global_block = new WriteOnce<bool>();
   _local_user = new SocialUser();
   _local_user.Certificate = certificate;
   _local_user.IP = _marad.LocalIP;
   _marad.AddDnsMapping(_local_user.Alias, _local_user.IP, true);
   _bso = AppNode.SecurityOverlord;
   _bso.CertificateHandler.AddCACertificate(_local_user.GetCert().X509);
   _bso.CertificateHandler.AddSignedCertificate(_local_user.GetCert().X509);
 }