Beispiel #1
0
void link_free(gpointer data) {
	Link* link = data;
	MAGIC_ASSERT(link);

	MAGIC_CLEAR(link);
	g_free(link);
}
Beispiel #2
0
void host_free(Host* host, gpointer userData) {
	MAGIC_ASSERT(host);

	g_queue_free(host->applications);

	topology_detach(worker_getTopology(), networkinterface_getAddress(host->defaultInterface));

	g_hash_table_destroy(host->interfaces);
	g_hash_table_destroy(host->descriptors);
	g_hash_table_destroy(host->shadowToOSHandleMap);
	g_hash_table_destroy(host->osToShadowHandleMap);
	g_hash_table_destroy(host->unixPathToPortMap);

	g_free(host->name);

	eventqueue_free(host->events);
	cpu_free(host->cpu);
	tracker_free(host->tracker);

	g_queue_free(host->availableDescriptors);

	g_mutex_clear(&(host->lock));

	MAGIC_CLEAR(host);
	g_free(host);
}
Beispiel #3
0
void socket_free(gpointer data) {
    Socket* socket = data;
    MAGIC_ASSERT(socket);
    MAGIC_ASSERT(socket->vtable);


    if(socket->peerString) {
        g_free(socket->peerString);
    }
    if(socket->boundString) {
        g_free(socket->boundString);
    }
    if(socket->unixPath) {
        g_free(socket->unixPath);
    }

    while(g_queue_get_length(socket->inputBuffer) > 0) {
        packet_unref(g_queue_pop_head(socket->inputBuffer));
    }
    g_queue_free(socket->inputBuffer);

    while(g_queue_get_length(socket->outputBuffer) > 0) {
        packet_unref(g_queue_pop_head(socket->outputBuffer));
    }
    g_queue_free(socket->outputBuffer);

    MAGIC_CLEAR(socket);
    socket->vtable->free((Descriptor*)socket);
}
void networkinterface_free(NetworkInterface* interface) {
	MAGIC_ASSERT(interface);

	/* unref all packets sitting in our input buffer */
	while(interface->inBuffer && !g_queue_is_empty(interface->inBuffer)) {
		Packet* packet = g_queue_pop_head(interface->inBuffer);
		packet_unref(packet);
	}
	g_queue_free(interface->inBuffer);

	/* unref all sockets wanting to send */
	while(interface->rrQueue && !g_queue_is_empty(interface->rrQueue)) {
		Socket* socket = g_queue_pop_head(interface->rrQueue);
		descriptor_unref(socket);
	}
	g_queue_free(interface->rrQueue);

	priorityqueue_free(interface->fifoQueue);

	g_hash_table_destroy(interface->boundSockets);

	dns_deregister(worker_getDNS(), interface->address);
	address_unref(interface->address);

	if(interface->pcapFile) {
		fclose(interface->pcapFile);
	}

	MAGIC_CLEAR(interface);
	g_free(interface);
}
Beispiel #5
0
void tcp_free(TCP* tcp) {
	MAGIC_ASSERT(tcp);

	while(g_queue_get_length(tcp->throttledOutput) > 0) {
		packet_unref(g_queue_pop_head(tcp->throttledOutput));
	}
	g_queue_free(tcp->throttledOutput);

	while(g_queue_get_length(tcp->unorderedInput) > 0) {
		packet_unref(g_queue_pop_head(tcp->unorderedInput));
	}
	g_queue_free(tcp->unorderedInput);

	g_hash_table_destroy(tcp->retransmission);

	if(tcp->child) {
		MAGIC_ASSERT(tcp->child);
		MAGIC_ASSERT(tcp->child->parent);
		MAGIC_ASSERT(tcp->child->parent->server);

		/* remove parents reference to child, if it exists */
		g_hash_table_remove(tcp->child->parent->server->children, &(tcp->child->key));

		_tcpchild_free(tcp->child);
	}

	if(tcp->server) {
		_tcpserver_free(tcp->server);
	}

	MAGIC_CLEAR(tcp);
	g_free(tcp);
}
Beispiel #6
0
void transport_free(Transport* transport) {
	MAGIC_ASSERT(transport);
	MAGIC_ASSERT(transport->vtable);

	MAGIC_CLEAR(transport);
	transport->vtable->free((Descriptor*)transport);
}
Beispiel #7
0
static void _scheduler_free(Scheduler* scheduler) {
    MAGIC_ASSERT(scheduler);

    guint nWorkers = g_queue_get_length(scheduler->threadItems);

    while(!g_queue_is_empty(scheduler->threadItems)) {
        SchedulerThreadItem* item = g_queue_pop_head(scheduler->threadItems);
        countdownlatch_free(item->notifyDoneRunning);
        g_free(item);
    }

    g_queue_free(scheduler->threadItems);

    scheduler->policy->free(scheduler->policy);
    random_free(scheduler->random);

    countdownlatch_free(scheduler->executeEventsBarrier);
    countdownlatch_free(scheduler->collectInfoBarrier);
    countdownlatch_free(scheduler->prepareRoundBarrier);
    countdownlatch_free(scheduler->startBarrier);
    countdownlatch_free(scheduler->finishBarrier);

    if(scheduler->threadToWaitTimerMap) {
        g_hash_table_destroy(scheduler->threadToWaitTimerMap);
    }

    g_mutex_clear(&(scheduler->globalLock));

    message("%i worker threads finished", nWorkers);

    MAGIC_CLEAR(scheduler);
    g_free(scheduler);
}
Beispiel #8
0
static void channel_free(Channel* channel) {
	MAGIC_ASSERT(channel);

	bytequeue_free(channel->buffer);

	MAGIC_CLEAR(channel);
	g_free(channel);
}
Beispiel #9
0
void tracker_free(Tracker* tracker) {
	MAGIC_ASSERT(tracker);

	g_hash_table_destroy(tracker->allocatedLocations);

	MAGIC_CLEAR(tracker);
	g_free(tracker);
}
void tcpretransmittimerexpired_free(TCPRetransmitTimerExpiredEvent* event) {
	MAGIC_ASSERT(event);

	descriptor_unref(event->tcp);

	MAGIC_CLEAR(event);
	g_free(event);
}
Beispiel #11
0
void parser_free(Parser* parser) {
	MAGIC_ASSERT(parser);

	/* cleanup */
	g_markup_parse_context_free(parser->context);

	MAGIC_CLEAR(parser);
	g_free(parser);
}
Beispiel #12
0
void tracker_free(Tracker* tracker) {
    MAGIC_ASSERT(tracker);

    g_hash_table_foreach(tracker->allocatedLocations, _tracker_freeAllocatedLocations, NULL);
    g_hash_table_destroy(tracker->allocatedLocations);
    g_hash_table_destroy(tracker->socketStats);

    MAGIC_CLEAR(tracker);
    g_free(tracker);
}
Beispiel #13
0
void software_free(gpointer data) {
	Software* software = data;
	MAGIC_ASSERT(software);

	g_string_free(software->arguments, TRUE);
	g_string_free(software->pluginPath, TRUE);

	MAGIC_CLEAR(software);
	g_free(software);
}
Beispiel #14
0
static void _address_free(Address* address) {
    MAGIC_ASSERT(address);

    g_free(address->ipString);
    g_free(address->name);
    g_free(address->idString);

    MAGIC_CLEAR(address);
    g_free(address);
}
Beispiel #15
0
void worker_free(gpointer data) {
	Worker* worker = data;
	MAGIC_ASSERT(worker);

	/* calls the destroy functions we specified in g_hash_table_new_full */
	g_hash_table_destroy(worker->plugins);

	MAGIC_CLEAR(worker);
	g_free(worker);
}
Beispiel #16
0
static void _tcpserver_free(TCPServer* server) {
	MAGIC_ASSERT(server);

	/* no need to destroy children in this queue */
	g_queue_free(server->pending);
	/* this will unref all children */
	g_hash_table_destroy(server->children);

	MAGIC_CLEAR(server);
	g_free(server);
}
Beispiel #17
0
static void _tcpchild_free(TCPChild* child) {
	MAGIC_ASSERT(child);

	/* make sure our tcp doesnt try to free the child again */
	child->tcp->child = NULL;
	descriptor_unref(child->tcp);
	descriptor_unref(child->parent);

	MAGIC_CLEAR(child);
	g_free(child);
}
Beispiel #18
0
static void _epollwatch_free(gpointer data) {
	EpollWatch* watch = data;
	MAGIC_ASSERT(watch);

	descriptor_removeStatusListener(watch->descriptor, watch->listener);
	listener_free(watch->listener);
	descriptor_unref(watch->descriptor);

	MAGIC_CLEAR(watch);
	g_free(watch);
}
Beispiel #19
0
static void _descriptor_free(Descriptor* descriptor) {
    MAGIC_ASSERT(descriptor);
    MAGIC_ASSERT(descriptor->funcTable);


    if(descriptor->readyListeners) {
        g_slist_free(descriptor->readyListeners);
    }

    MAGIC_CLEAR(descriptor);
    descriptor->funcTable->free(descriptor);
}
Beispiel #20
0
void loadtopology_free(LoadTopologyAction* action) {
	MAGIC_ASSERT(action);

	if(action->path) {
		g_string_free(action->path, TRUE);
	}
	if(action->text) {
		g_string_free(action->text, TRUE);
	}

	MAGIC_CLEAR(action);
	g_free(action);
}
static void _schedulerpolicyhoststeal_free(SchedulerPolicy* policy) {
    MAGIC_ASSERT(policy);
    HostStealPolicyData* data = policy->data;

    g_hash_table_destroy(data->hostToQueueDataMap);
    g_hash_table_destroy(data->threadToThreadDataMap);
    g_hash_table_destroy(data->hostToThreadMap);
    g_rw_lock_clear(&data->lock);
    g_free(data);

    MAGIC_CLEAR(policy);
    g_free(policy);
}
Beispiel #22
0
/* should only be called from descriptor dereferencing the functionTable */
static void _epoll_free(gpointer data) {
	Epoll* epoll = data;
	MAGIC_ASSERT(epoll);

	/* this will go through all epollwatch items and remove the listeners */
	g_hash_table_destroy(epoll->watches);
	g_hash_table_destroy(epoll->reports);

	close(epoll->osEpollDescriptor);

	MAGIC_CLEAR(epoll);
	g_free(epoll);
}
Beispiel #23
0
void internetwork_free(Internetwork* internet) {
	MAGIC_ASSERT(internet);

	/* now cleanup the rest */
	g_hash_table_destroy(internet->nodes);
	g_hash_table_destroy(internet->networks);
	g_hash_table_destroy(internet->networksByIP);
	g_hash_table_destroy(internet->ipByName);
	g_hash_table_destroy(internet->nameByIp);

	MAGIC_CLEAR(internet);
	g_free(internet);
}
Beispiel #24
0
void worker_free(Worker* worker) {
    MAGIC_ASSERT(worker);

    /* calls the destroy functions we specified in g_hash_table_new_full */
    g_hash_table_destroy(worker->privatePrograms);

    if(worker->serialEventQueue) {
        eventqueue_free(worker->serialEventQueue);
    }

    MAGIC_CLEAR(worker);
    g_private_set(&workerKey, NULL);
    g_free(worker);
}
Beispiel #25
0
static void _packet_free(Packet* packet) {
	MAGIC_ASSERT(packet);

	g_mutex_clear(&(packet->lock));
	if(packet->header) {
		g_free(packet->header);
	}
	if(packet->payload) {
		g_free(packet->payload);
	}

	MAGIC_CLEAR(packet);
	g_free(packet);
}
Beispiel #26
0
void process_free(Process* proc) {
    MAGIC_ASSERT(proc);

    process_stop(proc);

    g_string_free(proc->arguments, TRUE);

    if(proc->atExitFunctions) {
        g_queue_free_full(proc->atExitFunctions, g_free);
    }

    MAGIC_CLEAR(proc);
    g_free(proc);
}
Beispiel #27
0
void master_free(Master* master) {
    MAGIC_ASSERT(master);

    /* engine is now killed */
    master->killed = TRUE;

    GDateTime* dt_now = g_date_time_new_now_local();
    gchar* dt_format = g_date_time_format(dt_now, "%F %H:%M:%S");
    message("Shadow v%s shut down cleanly at %s", SHADOW_VERSION, dt_format);
    g_date_time_unref(dt_now);
    g_free(dt_format);

    random_free(master->random);

    MAGIC_CLEAR(master);
    g_free(master);
}
Beispiel #28
0
gint slave_free(Slave* slave) {
    MAGIC_ASSERT(slave);
    gint returnCode = (slave->numPluginErrors > 0) ? -1 : 0;

    /* this launches delete on all the plugins and should be called before
     * the engine is marked "killed" and workers are destroyed.
     */
    g_hash_table_destroy(slave->hosts);

    /* we will never execute inside the plugin again */
    slave->forceShadowContext = TRUE;

    if(slave->topology) {
        topology_free(slave->topology);
    }
    if(slave->dns) {
        dns_free(slave->dns);
    }

    g_hash_table_destroy(slave->programs);

    g_mutex_clear(&(slave->lock));
    g_mutex_clear(&(slave->pluginInitLock));

    /* join and free spawned worker threads */
//TODO

    if(slave->cwdPath) {
        g_free(slave->cwdPath);
    }
    if(slave->dataPath) {
        g_free(slave->dataPath);
    }
    if(slave->hostsPath) {
        g_free(slave->hostsPath);
    }

    /* free main worker */
    worker_free(slave->mainThreadWorker);

    MAGIC_CLEAR(slave);
    g_free(slave);

    return returnCode;
}
Beispiel #29
0
void engine_free(Engine* engine) {
	MAGIC_ASSERT(engine);

	/* engine is now killed */
	engine->killed = TRUE;

	/* this launches delete on all the plugins and should be called before
	 * the engine is marked "killed" and workers are destroyed.
	 */
	internetwork_free(engine->internet);

	/* we will never execute inside the plugin again */
	engine->forceShadowContext = TRUE;

	if(engine->workerPool) {
		engine_teardownWorkerThreads(engine);
	}

	if(engine->masterEventQueue) {
		asyncpriorityqueue_free(engine->masterEventQueue);
	}

	registry_free(engine->registry);
	g_cond_free(engine->workersIdle);
	g_mutex_free(engine->engineIdle);

	GDateTime* dt_now = g_date_time_new_now_local();
	gchar* dt_format = g_date_time_format(dt_now, "%F %H:%M:%S:%N");
	message("clean engine shutdown at %s", dt_format);
	g_date_time_unref(dt_now);
	g_free(dt_format);

	for(int i = 0; i < engine->numCryptoThreadLocks; i++) {
		g_static_mutex_free(&(engine->cryptoThreadLocks[i]));
	}

	random_free(engine->random);
	g_mutex_free(engine->lock);

	MAGIC_CLEAR(engine);
	shadow_engine = NULL;
	g_free(engine);
}
Beispiel #30
0
void master_free(Master* master) {
    MAGIC_ASSERT(master);

    if(master->topology) {
        topology_free(master->topology);
    }
    if(master->dns) {
        dns_free(master->dns);
    }
    if(master->config) {
        configuration_free(master->config);
    }
    if(master->random) {
        random_free(master->random);
    }

    MAGIC_CLEAR(master);
    g_free(master);

    message("simulation master destroyed");
}