Пример #1
0
    static int WatchCallback(IntPtr ccns, IntPtr lhash, IntPtr rhash, IntPtr pname)
    {
        print("WatchCallback...");

        IntPtr uri = Egal.ccn_charbuf_create();

        Egal.ccn_charbuf Name = (Egal.ccn_charbuf)Marshal.PtrToStructure(pname, typeof(Egal.ccn_charbuf));
        Egal.ccn_uri_append(uri, Name.buf, Name.length, 1);

        IntPtr temp       = Egal.ccn_charbuf_as_string(uri);
        String PlayerName = Marshal.PtrToStringAnsi(temp);


        String ShortPlayerName = NameTrim(PlayerName);

        if (KnownCar(ShortPlayerName) == false && ShortPlayerName != me)
        {
            print("New Player Joined.");
        }
        else
        {
            print("Known Player.");
        }


        Egal.ccn_charbuf_destroy(ref uri);
        return(0);
    }
Пример #2
0
 void OnApplicationQuit()
 {
     print("quitting...");
     print("killing thread...");
     Egal.ccn_set_run_timeout(h, 0);
     oThread.Abort();
     oThread.Join();
 }
Пример #3
0
    public void run()
    {
        Thread t = Thread.CurrentThread;

        // print (t.IsAlive);
        while (t.IsAlive == true)
        {
            while (counter_for_run > 0)
            {
                ;
            }
            Egal.ccn_run(h, -1);
        }
    }
Пример #4
0
    IntPtr GetHandle()
    {
        // this is a C# expansion of Egal.GetHandle()
        IntPtr ccn = Egal.ccn_create();

        if (Egal.ccn_connect(ccn, "") == -1)
        {
            print("could not connect to ccnd.\n");
        }
        else
        {
            print("a handle is connected to ccnd.");
        }
        return(ccn);
    }
Пример #5
0
    int WatchOverRepo(IntPtr h, string p, string t)
    {
        // this is a C# expansion of Egal.WatchOverRepo
        int    res;
        IntPtr prefix = Egal.ccn_charbuf_create();
        IntPtr topo   = Egal.ccn_charbuf_create();

        Egal.ccn_name_init(prefix);
        Egal.ccn_name_init(topo);

        res = Egal.ccn_name_from_uri(prefix, p);
        if (res < 0)
        {
            print("Prefix not right");
            return(res);
        }

        res = Egal.ccn_name_from_uri(topo, t);
        if (res < 0)
        {
            print("Topo not right");
            return(res);
        }

        int timeout = TIMEOUT;

        if (timeout < -1)
        {
            print("Timeout cannot be less than -1");
            return(-1);
        }
        timeout *= 1000;

        IntPtr slice = Egal.ccns_slice_create();

        Egal.ccns_slice_set_topo_prefix(slice, topo, prefix);

        IntPtr ccns = Egal.ccns_open(h, slice, WatchCallback, IntPtr.Zero, IntPtr.Zero);

        // ccns_close(&ccns, NULL, NULL);

        Egal.ccns_slice_destroy(ref slice);

        return(res);
    }
Пример #6
0
    int WriteSlice(IntPtr h, System.String p, System.String t)
    {
        // this is a C# expansion of Egal.WriteSlice
        int    res;
        IntPtr prefix = Egal.ccn_charbuf_create();
        IntPtr topo   = Egal.ccn_charbuf_create();

        Egal.ccn_name_init(prefix);
        Egal.ccn_name_init(topo);

        res = Egal.ccn_name_from_uri(prefix, p);
        if (res < 0)
        {
            print("Prefix not right");
            return(res);
        }

        res = Egal.ccn_name_from_uri(topo, t);
        if (res < 0)
        {
            print("Topo not right");
            return(res);
        }

        int timeout = TIMEOUT;

        if (timeout < -1)
        {
            print("Timeout cannot be less than -1");
            return(-1);
        }
        timeout *= 1000;

        IntPtr slice = Egal.ccns_slice_create();

        Egal.ccns_slice_set_topo_prefix(slice, topo, prefix);

        res = Egal.ccns_write_slice(h, slice, prefix);

        Egal.ccns_slice_destroy(ref slice); // after this, slice == 0

        return(res);
    }
Пример #7
0
    void WriteToRepo(IntPtr h, System.String name, System.String content)
    {
        print("Writing " + name + " to repo: " + content);

        int res;

        IntPtr cb  = Egal.ccn_charbuf_create();
        IntPtr nm  = Egal.ccn_charbuf_create();
        IntPtr cmd = Egal.ccn_charbuf_create();

        Egal.ccn_name_from_uri(nm, name);
        Egal.ccn_create_version(h, nm, VersioningFlags.CCN_V_NOW, 0, 0);

        NormalStruct Data  = new NormalStruct(nm, cb, h, content.Length, content);
        IntPtr       pData = Marshal.AllocHGlobal(Marshal.SizeOf(Data));

        Marshal.StructureToPtr(Data, pData, true);

        IntPtr template = Egal.SyncGenInterest(IntPtr.Zero, 1, 4, -1, -1, IntPtr.Zero);

        Egal.ccn_closure Action = new Egal.ccn_closure(WriteCallback, pData, 0);
        IntPtr           pnt    = Marshal.AllocHGlobal(Marshal.SizeOf(Action));

        Marshal.StructureToPtr(Action, pnt, true);

        res = Egal.ccn_set_interest_filter(h, nm, pnt);         // listen: interest

        res = Egal.ccn_charbuf_append_charbuf(cmd, nm);
        res = Egal.ccn_name_from_uri(cmd, "%C1.R.sw");
        Egal.ccn_name_append_nonce(cmd);

        counter_for_run++;
        res = Egal.ccn_set_run_timeout(h, 0);
        Egal.ccn_express_interest(h, cmd, pnt, template);         // express interest
        counter_for_run--;

        return;
    }
Пример #8
0
    int RegisterInterestFilter(IntPtr h, string name)
    {
        int    res = 0;
        IntPtr nm  = Egal.ccn_charbuf_create();

        res = Egal.ccn_name_from_uri(nm, name);
        if (res < 0)
        {
            return(res);
        }

        NormalStruct State  = new NormalStruct(nm, IntPtr.Zero, h, 0, "");
        IntPtr       pState = Marshal.AllocHGlobal(Marshal.SizeOf(State));

        Marshal.StructureToPtr(State, pState, true);

        Egal.ccn_closure Action  = new Egal.ccn_closure(PublishState, pState, 0);
        IntPtr           pAction = Marshal.AllocHGlobal(Marshal.SizeOf(Action));

        Marshal.StructureToPtr(Action, pAction, true);

        res = Egal.ccn_set_interest_filter(h, nm, pAction);
        return(res);
    }
Пример #9
0
    int PutContent(IntPtr h, NormalStruct Data)
    {
        int res = 0;

        Egal.ccn_charbuf Nm = new Egal.ccn_charbuf();
        Nm = (Egal.ccn_charbuf)Marshal.PtrToStructure(Data.nm, typeof(Egal.ccn_charbuf));

        IntPtr uri = Egal.ccn_charbuf_create();

        Egal.ccn_uri_append(uri, Nm.buf, Nm.length, 0);

        IntPtr name = Egal.SyncCopyName(Data.nm);
        IntPtr cb   = Egal.ccn_charbuf_create();
        IntPtr cob  = Egal.ccn_charbuf_create();

        Egal.ccn_charbuf_append(cb, Data.value, Data.vSize);
        Egal.ccn_charbuf Cb = new Egal.ccn_charbuf();
        Cb = (Egal.ccn_charbuf)Marshal.PtrToStructure(cb, typeof(Egal.ccn_charbuf));

        Egal.ccn_signing_params Sp = new Egal.ccn_signing_params(CCN.CCN_API_VERSION);
        Sp.sp_flags |= SP.signingparameters.CCN_SP_FINAL_BLOCK;
        IntPtr pSp = Marshal.AllocHGlobal(Marshal.SizeOf(Sp));

        Marshal.StructureToPtr(Sp, pSp, true);

        /*
         * // test zone
         * Egal.ccn_signing_params Test = new Egal.ccn_signing_params(CCN.CCN_API_VERSION);
         * IntPtr pTest = Marshal.AllocHGlobal(Marshal.SizeOf(Test));
         * Marshal.StructureToPtr(Test, pTest, true);
         * IntPtr a = IntPtr.Zero;
         * IntPtr b = IntPtr.Zero;
         * IntPtr c = IntPtr.Zero;
         * res = Egal.ccn_chk_signing_params(h, pSp, pTest, ref a, ref b, ref c);
         * print ("check result: " + res);
         * // test zone end
         */

        // Data.ccn, Cb.buf, Data.vSize is correct
        res |= Egal.ccn_sign_content(h, cob, name, pSp, Cb.buf, Data.vSize);
        if (res < 0)
        {
            print("sign content error.");
        }

        Egal.ccn_charbuf Cob = new Egal.ccn_charbuf();
        Cob  = (Egal.ccn_charbuf)Marshal.PtrToStructure(cob, typeof(Egal.ccn_charbuf));
        res |= Egal.ccn_put(Data.ccn, Cob.buf, Cob.length);
        if (res < 0)
        {
            print("ccn_put error.");
        }

        // cleanup
        Egal.ccn_charbuf_destroy(ref uri);
        Egal.ccn_charbuf_destroy(ref name);
        Egal.ccn_charbuf_destroy(ref cb);
        Egal.ccn_charbuf_destroy(ref cob);
        Marshal.FreeHGlobal(pSp);

        return(res);
    }
Пример #10
0
    // ExpressInterest()
    // takes handle, name, callback and template
    public static int ExpressInterest(IntPtr ccn, string name, Egal.ccn_handler callback, IntPtr pData, IntPtr template)
    {
        IntPtr nm = Egal.ccn_charbuf_create();
        Egal.ccn_name_from_uri(nm,name);
        Egal.ccn_closure Action = new Egal.ccn_closure(callback, pData, 0);
        IntPtr pnt = Marshal.AllocHGlobal(Marshal.SizeOf(Action));
        Marshal.StructureToPtr(Action, pnt, true);

        Egal.ccn_express_interest(ccn,nm,pnt,template);

        return 0;
    }