Ejemplo n.º 1
0
        /** Return the edge specified in the given URI
         * this matches the SenderFactory
         */
        public static Edge CreateInstance(object n, string uri)
        {
            string scheme;
            IDictionary <string, string> args = SenderFactory.DecodeUri(uri, out scheme);

            return(GetEdgeNum(Int64.Parse(args["num"])));
        }
Ejemplo n.º 2
0
        protected static AHSender CreateInstance(object node_ctx, string uri)
        {
            Node   n = (Node)node_ctx;
            string ahscheme; //Should be "ah"
            IDictionary <string, string> kvpairs = SenderFactory.DecodeUri(uri, out ahscheme);
            Address target = AddressParser.Parse("brunet:node:" + kvpairs["dest"]);
            ushort  option = AHHeader.Options.StringToUShort(kvpairs["mode"]);

            return(new AHSender(n, target, option));
        }
Ejemplo n.º 3
0
        public static ForwardingSender CreateInstance(object node_ctx, string uri)
        {
            Node   n = (Node)node_ctx;
            string fw_scheme; //Should be "fw"
            IDictionary <string, string> kvpairs = SenderFactory.DecodeUri(uri, out fw_scheme);
            Address forwarder   = AddressParser.Parse("brunet:node:" + kvpairs["relay"]);
            ushort  init_option = AHHeader.Options.StringToUShort(kvpairs["init_mode"]);
            Address target      = AddressParser.Parse("brunet:node:" + kvpairs["dest"]);
            short   ttl         = (short)Int16.Parse(kvpairs["ttl"]);
            ushort  option      = AHHeader.Options.StringToUShort(kvpairs["mode"]);

            //Console.WriteLine("{0}, {1}, {2}, {3}, {4}", forwarder, init_option, target, ttl, option);
            return(new ForwardingSender(n, forwarder, init_option, target, ttl, option));
        }
Ejemplo n.º 4
0
        public void Test()
        {
            RandomNumberGenerator rng     = new RNGCryptoServiceProvider();
            AHAddress             tmp_add = new AHAddress(rng);
            Node             n            = new StructuredNode(tmp_add, "unittest");
            AHSender         ah           = new AHSender(n, AddressParser.Parse("brunet:node:JOJZG7VO6RFOEZJ6CJJ2WOIJWTXRVRP4"));
            ForwardingSender fs           = new ForwardingSender(n,
                                                                 AddressParser.Parse("brunet:node:JOJZG7VO6RFOEZJ6CJJ2WOIJWTXRVRP4"),
                                                                 AddressParser.Parse("brunet:node:5FMQW3KKJWOOGVDO6QAQP65AWVZQ4VUQ"));

            string  uri = "sender:ah?dest=JOJZG7VO6RFOEZJ6CJJ2WOIJWTXRVRP4&mode=exact";
            ISender s   = SenderFactory.CreateInstance(n, uri);

            Assert.IsTrue(s is AHSender);
            Assert.AreEqual(uri, s.ToUri());
            uri = "sender:ah?dest=JOJZG7VO6RFOEZJ6CJJ2WOIJWTXRVRP4&mode=greedy";

            //Create the above programatically
            IDictionary <string, string> param_args = new Dictionary <string, string>();

            param_args["dest"] = "JOJZG7VO6RFOEZJ6CJJ2WOIJWTXRVRP4";
            param_args["mode"] = "greedy";
            string uri0 = SenderFactory.EncodeUri("ah", param_args);

            Assert.AreEqual(uri, uri0, "EncodeUri works");
            //Check decode:
            string scheme;

            param_args = SenderFactory.DecodeUri(uri, out scheme);
            Assert.AreEqual(scheme, "ah", "Scheme decoded");
            Assert.AreEqual(param_args.Count, 2, "2 parameters in uri");
            Assert.AreEqual(param_args["dest"], "JOJZG7VO6RFOEZJ6CJJ2WOIJWTXRVRP4", "Extracted address");
            Assert.AreEqual(param_args["mode"], "greedy", "got mode");

            s = SenderFactory.CreateInstance(n, uri);
            Assert.IsTrue(s is AHSender);
            Assert.AreEqual(uri, s.ToUri());
            string furi = "sender:fw?relay=JOJZG7VO6RFOEZJ6CJJ2WOIJWTXRVRP4&init_mode=greedy&dest=5FMQW3KKJWOOGVDO6QAQP65AWVZQ4VUQ&ttl=3&mode=path";

            s = SenderFactory.CreateInstance(n, furi);
            Assert.IsTrue(s is ForwardingSender);
            Assert.AreEqual(furi, s.ToUri());
        }