コード例 #1
0
ファイル: fun.c プロジェクト: digideskio/pginstall
Datum
pginstall_available_extensions(PG_FUNCTION_ARGS)
{
    ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
    TupleDesc   tupdesc;
    Tuplestorestate *tupstore;
    MemoryContext per_query_ctx;
    MemoryContext oldcontext;
    List *extensions = NIL;
    ListCell *lc;
    PlatformData platform;

    /* Fetch the list of available extensions */
    current_platform(&platform);

    if (pginstall_serve_from_archive_dir)
        extensions = list_available_extensions_in_archive_dir(&platform);

    /*
     * Don't duplicate extensions (based on shortname), keep only the local
     * cache one in case of duplicates.
     *
     * XXX: expensive algorithm, we might want to switch to using hash tables
     * here at some point.
     */
    if (pginstall_repository != NULL && strcmp(pginstall_repository, "") != 0)
    {
        List *repo_exts = list_available_extensions_on_repository(&platform);

        if (extensions == NIL)
            extensions = repo_exts;
        else
        {
            List *keep = NIL;
            ListCell *lc2;

            foreach(lc, repo_exts)
            {
                pginstall_extension *ext = (pginstall_extension *) lfirst(lc);

                bool keep_this_one = true;

                foreach(lc2, extensions)
                {
                    pginstall_extension *ext2 =
                        (pginstall_extension *) lfirst(lc2);

                    if (strcmp(ext->shortname, ext2->shortname) == 0)
                    {
                        keep_this_one = false;
                        break;
                    }
                    if (keep_this_one)
                        keep = lappend(keep, ext);
                }
            }
コード例 #2
0
ファイル: main.cpp プロジェクト: zeeshanabid94/ENCODERS
int run_haggle()
{
	srand(time(NULL));
#ifdef ENABLE_DEBUG_MANAGER
	DebugManager *db = NULL;
#endif
	ApplicationManager *am = NULL;
	DataManager *dm = NULL;
// SW: START: SendPriorityManager
	SendPriorityManager *spm = NULL;
// SW: END: SendPriorityManager
	NodeManager *nm = NULL;
	ProtocolManager *pm = NULL;
	ForwardingManager *fm = NULL;
	SecurityManager *sm = NULL;
	ConnectivityManager *cm = NULL;
	LossEstimateManager *lm = NULL;
	NetworkCodingManager* networkCodingManager = NULL;
	FragmentationManager* fragmentationManager = NULL;
	//JM
	ReplicationManager *replicationManager = NULL;
	BenchmarkManager *bm = NULL;
	ResourceManager *rm = NULL;
// SW: START: interest manager
    InterestManager *im = NULL;
// SW: END: interest manager

	ProtocolSocket *p = NULL;
#ifdef OS_WINDOWS_MOBILE

	// For testing we force the deletion of the data store
	//recreateDataStore = true;
#endif
	int retval = EXIT_FAILURE;

#if defined(OS_ANDROID)
	//mallopt(-1, -1); // MOS - avoid trimming
#elif defined(OS_LINUX)
        mallopt(M_TRIM_THRESHOLD, -1); // MOS - avoid trimming
#endif

	xmlInitParser(); // MOS - this need to be called here for thread-safe libxml use

#ifdef DEBUG
    Trace::trace.enableFileTrace();
#endif

	HAGGLE_LOG("\n\n****************** HAGGLE STARTUP *********************\n\n");

	if (!create_path(HAGGLE_DEFAULT_STORAGE_PATH)) {
                HAGGLE_ERR("Could not create Haggle storage path : %s\n", HAGGLE_DEFAULT_STORAGE_PATH);
                return -1;
        }
	
        retval = write_pid_file(getpid());

        if (retval != HAGGLE_PROCESS_NO_ERROR) {
                switch (retval) {
                        case HAGGLE_PROCESS_BAD_PID:
                                HAGGLE_ERR("Cannot read PID file %s.\n", PID_FILE.c_str());
                                break;
                        case HAGGLE_PROCESS_CANNOT_WRITE_PID:
                                HAGGLE_ERR("Cannot write PID file %s\n", PID_FILE.c_str());
                                break;
                        case HAGGLE_PROCESS_ALREADY_RUNNING: 
                                HAGGLE_ERR("PID file %s indicates that Haggle is already running.\n", PID_FILE.c_str());
                                break;
                        default:
                                HAGGLE_ERR("Unknown PID file error\n");

                }
                shouldCleanupPidFile = false;
                return -1;
        }
#if defined(OS_UNIX) && !defined(OS_ANDROID)
	setrawtty();
#endif
      
        /* Seed the random number generator */
	prng_init();

// SW: START CONFIG PATH (instead of hardcoded ~/.Haggle/config.xml),
    if (useMemoryDB) {
        kernel = new HaggleKernel(configFile, new MemoryDataStore(recreateDataStore));
    }
    else {
        kernel = new HaggleKernel(configFile, new SQLDataStore(recreateDataStore));
    }
// SW: END CONFIG PATH.

	if (!kernel || !kernel->init()) {
		fprintf(stderr, "Kernel initialization error!\n");
		return -1;
	}
	
	// Build a Haggle configuration
	am = new ApplicationManager(kernel);

	if (!am || !am->init()) {
		HAGGLE_ERR("Could not initialize application manager\n");
		goto finish;
	}

	dm = new DataManager(kernel, setCreateTimeOnBloomfilterUpdate);

	if (!dm || !dm->init()) {
		HAGGLE_ERR("Could not initialize data manager\n");
		goto finish;
	}

// SW: START: SendPriorityManager
    spm = new SendPriorityManager(kernel);
    if (!spm || !spm->init()) {
        HAGGLE_ERR("Could not initialize send priority manager\n");
        goto finish;
    }
// SW: END: SendPriorityManager

	nm = new NodeManager(kernel);

	if (!nm || !nm->init()) {
		HAGGLE_ERR("Could not initialize node manager\n");
		goto finish;
	}

	pm = new ProtocolManager(kernel);

	if (!pm || !pm->init()) {
		HAGGLE_ERR("Could not initialize protocol manager\n");
		goto finish;
	}

	fm = new ForwardingManager(kernel);

	if (!fm || !fm->init()) {
		HAGGLE_ERR("Could not initialize forwarding manager\n");
		goto finish;
	}

	sm = new SecurityManager(kernel, securityLevel);

	if (!sm || !sm->init()) {
		HAGGLE_ERR("Could not initialize security manager\n");
		goto finish;
	}
	fragmentationManager = new FragmentationManager(kernel);
	if(!fragmentationManager || !fragmentationManager->init()) {
	    HAGGLE_ERR("Could not initialize fragmentationManager\n");
	    goto finish;
	}

	networkCodingManager = new NetworkCodingManager(kernel);
	if(!networkCodingManager || !networkCodingManager->init()) {
	    HAGGLE_ERR("Could not initialize networkCodingManager \n");
	    goto finish;
	}

	//JM
	replicationManager = new ReplicationManager(kernel);
        if (!replicationManager || !replicationManager->init()) {
		HAGGLE_ERR("Could not initialize replication manager\n");
		goto finish;
    }
    
	lm = new LossEstimateManager(kernel);
	if(!lm || !lm->init()){
	    HAGGLE_ERR("Could not initialize LossEstimateManager \n");
	    goto finish;		
	}

#ifdef USE_UNIX_APPLICATION_SOCKET
	p = new ProtocolLOCAL(kernel->getStoragePath() + "/" + HAGGLE_LOCAL_SOCKET, pm);

	if (!p || !p->init()) {
		HAGGLE_ERR("Could not initialize LOCAL protocol\n");
		goto finish;
	}
	p->setFlag(PROT_FLAG_APPLICATION);
	p->registerWithManager();

#endif
	p = new ProtocolUDP("127.0.0.1", HAGGLE_SERVICE_DEFAULT_PORT, pm);
	/* Add ConnectivityManager last since it will start to
	* discover interfaces and generate events. At that
	* point the other managers should already be
	* running. */

	if (!p || !p->init()) {
		HAGGLE_ERR("Could not initialize UDP Application protocol\n");
		goto finish;
	}
	p->setFlag(PROT_FLAG_APPLICATION);
	p->registerWithManager();

// SW: start interest manager
    im = new InterestManager(kernel);

    if (!im || !im->init()) {
        HAGGLE_ERR("Could not initialize interest manager\n");
        goto finish;
    }
// SW: end interest manager

	/* MOS - disable resource mananager due 
	   high cpu utilization bug on Android

	rm = new ResourceManager(kernel);

	if (!rm || !rm->init()) {
		HAGGLE_ERR("Could not initialize resource manager\n");
		goto finish;
	}

	*/

	if (!isBenchmarking) {
		cm = new ConnectivityManager(kernel);

		if (!cm || !cm->init()) {
			HAGGLE_ERR("Could not initialize connectivity manager\n");
			goto finish;
		}

	} else {
		bm = new BenchmarkManager(kernel, Benchmark_DataObjects_Attr, Benchmark_Nodes_Attr, Benchmark_Attr_Num, Benchmark_DataObjects_Num, Benchmark_Test_Num);

		if (!bm || !bm->init()) {
			HAGGLE_ERR("Could not initialize benchmark manager\n");
			goto finish;
		}
	}
#if defined(ENABLE_DEBUG_MANAGER)
	// It seems as if there can be only one accept() per
	// thread... we need to make the DebugManager register
	// protocol or something with the ProtocolTCPServer
	// somehow
	db = new DebugManager(kernel, runAsInteractive);

	if (!db || !db->init()) {
		HAGGLE_ERR("Could not initialize debug manager\n");
		/* Treat as non critical error. */
	}
#endif

	HAGGLE_DBG("Starting Haggle...\n");

#ifdef OS_WINDOWS_MOBILE
	if (platform_type(current_platform()) == platform_windows_mobile_professional)
		tray_notification_add(g_hInstance, kernel);
#endif

	kernel->run();

	if(kernel->hasFatalError()) retval = EXIT_FAILURE;
	else retval = EXIT_SUCCESS;

	HAGGLE_DBG("Haggle finished...\n");

finish:
	if (bm)
		delete bm;
	if (lm)
		delete lm;

	if (fragmentationManager) {
	    delete fragmentationManager;
	    fragmentationManager = NULL;
	}
	if (networkCodingManager)
	    delete networkCodingManager;
	//JM
	if (replicationManager)
	  	delete replicationManager;
	if (cm)
		delete cm;
	if (sm)
		delete sm;
	if (fm)
		delete fm;
	if (pm)	
		delete pm;
	if (nm)
		delete nm;
	if (dm)
		delete dm;
// SW: START: SendPriorityManager
    if (spm)
        delete spm;
// SW: END: SendPriorityManager
	if (am)
		delete am;
// SW: start interest manager
    if (im)
        delete im;
// SW: end interest manager
#if defined(ENABLE_DEBUG_MANAGER)
	if (db)
		delete db;
#endif
	if (rm)
		delete rm;

#ifdef OS_WINDOWS_MOBILE
	tray_notification_remove();
#endif
	delete kernel;
	kernel = NULL;

	xmlCleanupParser(); // MOS

	return retval;
}
コード例 #3
0
ファイル: pgarchive.c プロジェクト: digideskio/pginstall
/*
 * At CREATE EXTENSION time we check if the extension is already available,
 * which is driven by the presence of its control file on disk.
 *
 * If the extension is not already available, we ask the repository server for
 * it, and unpack received binary archive to the right place.
 *
 * TODO: actually talk to the repository server. Current prototype version
 * directly uses the local archive cache.
 */
void
download_and_unpack_archive(const char *extname)
{
    PlatformData platform;
    char *control_filename = get_extension_control_filename(extname);
    char *archive_filename;

    /*
     * No cache, download again each time asked: any existing control file for
     * the extension could be one we left behind from a previous version of the
     * extension's archive.
     *
     * This also means that if an extension is already provided by the
     * operating system, by installing pginstall you give preference to
     * pginstall builds.
     */
    current_platform(&platform);
    archive_filename = psprintf("%s/%s--%s--%s--%s--%s.tar.gz",
                                pginstall_archive_dir,
                                extname,
                                PG_VERSION,
                                escape_filename(platform.os_name),
                                escape_filename(platform.os_version),
                                escape_filename(platform.arch));

    /*
     * The local repository might be added to directly by the pginstall build
     * client, and pginstall.serve_from_archive_dir allows to setup the
     * pginstall.archive_dir as a local authoritative source.
     *
     * Given that, we only download an archive file when
     *
     *  1. we have a pginstall.repository
     *  2. pginstall.serve_from_archive_dir is false
     *  3. pginstall.serve_from_archive_dir is true but we don't have the
     *     needed file locally
     */
    if (pginstall_repository != NULL && strcmp(pginstall_repository, "") != 0)
    {
        if (pginstall_serve_from_archive_dir
            && access(archive_filename, R_OK) == 0)
        {
            /* no download here. */
            (void)0;
        }
        else
        {
            download_archive(archive_filename, extname, &platform);
        }
    }

    /*
     * Even if we didn't find any extension's archive file for our platform on
     * the repository server, it could be that the extension is available
     * locally either through the OS packages or maybe a local developer setup
     * (make install).
     *
     * In case when when extension control file still doesn't exists after
     * we've been communicating with the repository server, PostgreSQL will
     * issue its usual error message about a missing control file.
     */
    if (access(archive_filename, R_OK) == 0)
    {
        extract(extname, archive_filename);

        /* now rewrite the control file to "relocate" the extension */
        rewrite_control_file(extname, control_filename);
    }
    return;
}
コード例 #4
0
ファイル: fun.c プロジェクト: digideskio/pginstall
Datum
pginstall_platform(PG_FUNCTION_ARGS)
{
    ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
    TupleDesc   tupdesc;
    Tuplestorestate *tupstore;
    MemoryContext per_query_ctx;
    MemoryContext oldcontext;
    PlatformData platform;
	Datum       values[3];
	bool        nulls[3];

    /* Fetch the list of available extensions */
    current_platform(&platform);

    /* check to see if caller supports us returning a tuplestore */
    if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
        ereport(ERROR,
                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                 errmsg("set-valued function called in context that cannot accept a set")));
    if (!(rsinfo->allowedModes & SFRM_Materialize))
        ereport(ERROR,
                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                 errmsg("materialize mode required, but it is not " \
                        "allowed in this context")));

    /* Build a tuple descriptor for our result type */
    if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
        elog(ERROR, "return type must be a row type");

    /* Build tuplestore to hold the result rows */
    per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
    oldcontext = MemoryContextSwitchTo(per_query_ctx);

    tupstore = tuplestore_begin_heap(true, false, work_mem);
    rsinfo->returnMode = SFRM_Materialize;
    rsinfo->setResult = tupstore;
    rsinfo->setDesc = tupdesc;

    MemoryContextSwitchTo(oldcontext);

	memset(values, 0, sizeof(values));
	memset(nulls, 0, sizeof(nulls));

	/* os name */
	values[0] = CStringGetTextDatum(platform.os_name);

	/* os version */
	values[1] = CStringGetTextDatum(platform.os_version);

	/* arch */
	values[2] = CStringGetTextDatum(platform.arch);

	tuplestore_putvalues(tupstore, tupdesc, values, nulls);

	/* clean up and return the tuplestore */
    tuplestore_donestoring(tupstore);

    return (Datum) 0;

}
コード例 #5
0
ファイル: main.cpp プロジェクト: eikoyoneki/haggle
int run_haggle()
{
#ifdef ENABLE_DEBUG_MANAGER
	DebugManager *db = NULL;
#endif
	ApplicationManager *am = NULL;
	DataManager *dm = NULL;
	NodeManager *nm = NULL;
	ProtocolManager *pm = NULL;
	ForwardingManager *fm = NULL;
	SecurityManager *sm = NULL;
	ConnectivityManager *cm = NULL;
#ifdef BENCHMARK
	BenchmarkManager *bm = NULL;
	//recreateDataStore = true;
#endif
	ResourceManager *rm = NULL;
	ProtocolSocket *p = NULL;
#ifdef OS_WINDOWS_MOBILE

	// For testing we force the deletion of the data store
	//recreateDataStore = true;
#endif
	int retval = EXIT_FAILURE;
	  
	if (!create_path(HAGGLE_DEFAULT_STORAGE_PATH)) {
                HAGGLE_ERR("Could not create Haggle storage path : %s\n", HAGGLE_DEFAULT_STORAGE_PATH);
                return -1;
        }
	
        retval = write_pid_file(getpid());

        if (retval != HAGGLE_PROCESS_NO_ERROR) {
                switch (retval) {
                        case HAGGLE_PROCESS_BAD_PID:
                                HAGGLE_ERR("Cannot read PID file %s.\n", PID_FILE.c_str());
                                break;
                        case HAGGLE_PROCESS_CANNOT_WRITE_PID:
                                HAGGLE_ERR("Cannot write PID file %s\n", PID_FILE.c_str());
                                break;
                        case HAGGLE_PROCESS_ALREADY_RUNNING: 
                                HAGGLE_ERR("PID file %s indicates that Haggle is already running.\n", PID_FILE.c_str());
                                break;
                        default:
                                HAGGLE_ERR("Unknown PID file error\n");

                }
                shouldCleanupPidFile = false;
                return -1;
        }
#if defined(OS_UNIX) && !defined(OS_ANDROID)
	setrawtty();
#endif
      
        /* Seed the random number generator */
	prng_init();

        kernel = new HaggleKernel(new SQLDataStore(recreateDataStore));

	if (!kernel || !kernel->init()) {
		fprintf(stderr, "Kernel initialization error!\n");
		return -1;
	}
	
	// Build a Haggle configuration
	am = new ApplicationManager(kernel);

	if (!am || !am->init()) {
		HAGGLE_ERR("Could not initialize application manager\n");
		goto finish;
	}

	dm = new DataManager(kernel, setCreateTimeOnBloomfilterUpdate);

	if (!dm || !dm->init()) {
		HAGGLE_ERR("Could not initialize data manager\n");
		goto finish;
	}

	nm = new NodeManager(kernel);

	if (!nm || !nm->init()) {
		HAGGLE_ERR("Could not initialize node manager\n");
		goto finish;
	}

	pm = new ProtocolManager(kernel);

	if (!pm || !pm->init()) {
		HAGGLE_ERR("Could not initialize protocol manager\n");
		goto finish;
	}

	fm = new ForwardingManager(kernel);

	if (!fm || !fm->init()) {
		HAGGLE_ERR("Could not initialize forwarding manager\n");
		goto finish;
	}

	sm = new SecurityManager(kernel, securityLevel);

	if (!sm || !sm->init()) {
		HAGGLE_ERR("Could not initialize security manager\n");
		goto finish;
	}

#ifdef USE_UNIX_APPLICATION_SOCKET
	p = new ProtocolLOCAL(kernel->getStoragePath() + "/" + HAGGLE_LOCAL_SOCKET, pm);
	
	if (!p || !p->init()) {
		HAGGLE_ERR("Could not initialize LOCAL protocol\n");
		goto finish;
	}
	p->setFlag(PROT_FLAG_APPLICATION);
	p->registerWithManager();

#endif
	p = new ProtocolUDP("127.0.0.1", HAGGLE_SERVICE_DEFAULT_PORT, pm);
	/* Add ConnectivityManager last since it will start to
	* discover interfaces and generate events. At that
	* point the other managers should already be
	* running. */

	if (!p || !p->init()) {
		HAGGLE_ERR("Could not initialize UDP Application protocol\n");
		goto finish;
	}
	p->setFlag(PROT_FLAG_APPLICATION);
	p->registerWithManager();

	rm = new ResourceManager(kernel);

	if (!rm || !rm->init()) {
		HAGGLE_ERR("Could not initialize resource manager\n");
		goto finish;
	}
#ifdef BENCHMARK
	if (!isBenchmarking) {
#endif
		cm = new ConnectivityManager(kernel);

		if (!cm || !cm->init()) {
			HAGGLE_ERR("Could not initialize connectivity manager\n");
			goto finish;
		}

#ifdef BENCHMARK
	} else {
		bm = new BenchmarkManager(kernel, Benchmark_DataObjects_Attr, Benchmark_Nodes_Attr, Benchmark_Attr_Num, Benchmark_DataObjects_Num, Benchmark_Test_Num);

		if (!bm || !bm->init()) {
			HAGGLE_ERR("Could not initialize benchmark manager\n");
			goto finish;
		}
	}
#endif
#if defined(ENABLE_DEBUG_MANAGER)
	// It seems as if there can be only one accept() per
	// thread... we need to make the DebugManager register
	// protocol or something with the ProtocolTCPServer
	// somehow
	db = new DebugManager(kernel, runAsInteractive);

	if (!db || !db->init()) {
		HAGGLE_ERR("Could not initialize debug manager\n");
		/* Treat as non critical error. */
	}
#endif

	HAGGLE_DBG("Starting Haggle...\n");

#ifdef OS_WINDOWS_MOBILE
	if (platform_type(current_platform()) == platform_windows_mobile_professional)
		tray_notification_add(g_hInstance, kernel);
#endif

	kernel->run();
	retval = EXIT_SUCCESS;

	HAGGLE_DBG("Haggle finished...\n");

finish:
#ifdef BENCHMARK
	if (bm)
		delete bm;
#endif
	if (cm)
		delete cm;
	if (sm)
		delete sm;
	if (fm)
		delete fm;
	if (pm)	
		delete pm;
	if (nm)
		delete nm;
	if (dm)
		delete dm;
	if (am)
		delete am;
#if defined(ENABLE_DEBUG_MANAGER)
	if (db)
		delete db;
#endif
	if (rm)
		delete rm;

#ifdef OS_WINDOWS_MOBILE
	tray_notification_remove();
#endif
	delete kernel;
	kernel = NULL;

	return retval;
}