///<summary>Verify the edge by comparing the address in the certificate to
    ///the one provided in the overlay.</summary>
    public static bool AddressInSubjectAltName(Node node, Edge e, Address addr) {
      SecureEdge se = e as SecureEdge;
      if(se == null) {
        throw new Exception("Invalid edge type!");
      }

      return se.SA.VerifyCertificateBySubjectAltName(addr.ToString());
    }
 private static string GetString(Address target, IEnumerable forwarders) {
   var sb = new System.Text.StringBuilder();
   sb.Append("brunet.tunnel://");
   sb.Append(target.ToString().Substring(12));
   sb.Append("/");
   foreach(object forwarder in forwarders) {
     Address addr = forwarder as Address;
     if(addr == null) {
       addr = (forwarder as Brunet.Connections.Connection).Address;
     }
     sb.Append(addr.ToString().Substring(12,8));
     sb.Append("+");
   }
   if(sb[sb.Length - 1] == '+') {
     sb.Remove(sb.Length - 1, 1);
   }
   return sb.ToString();
 }
    protected void SendRpcMessage(Address addr, string method, 
      string query, bool secure) {

      System.DateTime sent = System.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") {
              System.DateTime recv = System.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
    }
 /**
  * Callback function that is invoked when TargetSelector fetches candidate scores in a range.
  * Initiates connection setup. 
  * Node: All connection messages can be tagged with a token string. This token string is currenly being
  * used to keep the following information about a shortcut:
  * 1. The node who initiated the shortcut setup.
  * 2. The random target near which shortcut was chosen.
  * @param start address pointing to the start of range to query.
  * @param score_table list of candidate addresses sorted by score.
  * @param current currently selected optimal (nullable) 
  */
 protected void CreateShortcutCallback(Address start, SortedList score_table, Address current) {
   if (score_table.Count > 0) {
     /**
      * we remember our address and the start of range inside the token.
      * token is the concatenation of 
      * (a) local node address
      * (b) random target for the range queried by target selector
      */
     string token = _node.Address + start.ToString();
     //connect to the min_target
     Address min_target = (Address) score_table.GetByIndex(0);
     ISender send = null;
     if (start.Equals(min_target)) {
       //looks like the target selector simply returned our random address
       if (LogEnabled) {
         ProtocolLog.Write(ProtocolLog.SCO, 
                           String.Format("SCO local: {0}, Connecting (shortcut) to min_target: {1} (greedy), random_target: {2}.", 
                                         _node.Address, min_target, start));
       }
       //use a greedy sender
       send = new AHGreedySender(_node, min_target);
     } else {
       if (LogEnabled) {
         ProtocolLog.Write(ProtocolLog.SCO, 
                           String.Format("SCO local: {0}, Connecting (shortcut) to min_target: {1} (exact), random_target: {2}.", 
                               _node.Address, min_target, start));
       }
       //use exact sender
       send = new AHExactSender(_node, min_target);
     }
     ConnectTo(send, min_target, STRUC_SHORT, token);
   }
 }
 public bool ContainsForwarder(Address addr) {
   var test_mem = MemBlock.Reference(Base32.Decode(addr.ToString().Substring(12, 8)));
   return _forwarders.BinarySearch(test_mem) >= 0;
 }
Exemple #6
0
    public bool ContainsForwarder(Address addr) {
      MemBlock test_mem = MemBlock.Reference(Base32.Decode(addr.ToString().Substring(12, 8)));
      if (_forwarders.Contains(test_mem)) {
	return true;
      } 

      return false;
    }
Exemple #7
0
    private static string GetString(Address target, ArrayList forwarders) {
      string s = "brunet.tunnel://" +  
	target.ToString().Substring(12) + "/";
      for (int idx = 0; idx < forwarders.Count; idx++) {
	Address a = (Address) forwarders[idx];
	s +=  a.ToString().Substring(12,8);
	if (idx < forwarders.Count - 1) {
	  //not the last element
	  s = s + "+";
	}      
      }
      return s;
    }