예제 #1
0
파일: shd-tcp.c 프로젝트: icbaker/shadow
static TCPChild* _tcpchild_new(TCP* tcp, TCP* parent, in_addr_t peerIP, in_port_t peerPort) {
	MAGIC_ASSERT(tcp);
	MAGIC_ASSERT(parent);

	TCPChild* child = g_new0(TCPChild, 1);
	MAGIC_INIT(child);

	/* my parent can find me by my key */
	child->key = utility_ipPortHash(peerIP, peerPort);

	descriptor_ref(tcp);
	child->tcp = tcp;
	descriptor_ref(parent);
	child->parent = parent;

	child->state = TCPCS_INCOMPLETE;
	socket_setPeerName(&(child->tcp->super), peerIP, peerPort);

	/* the child is bound to the parent server's address, because all packets
	 * coming from the child should appear to be coming from the server itself */
	socket_setSocketName(&(child->tcp->super), socket_getBinding(&(parent->super)),
			parent->super.boundPort);

	return child;
}
예제 #2
0
void networkinterface_wantsSend(NetworkInterface* interface, Socket* socket) {
	MAGIC_ASSERT(interface);

	/* track the new socket for sending if not already tracking */
	switch(interface->qdisc) {
		case NIQ_RR: {
			if(!g_queue_find(interface->rrQueue, socket)) {
				descriptor_ref(socket);
				g_queue_push_tail(interface->rrQueue, socket);
			}
			break;
		}
		case NIQ_FIFO:
		default: {
			if(!priorityqueue_find(interface->fifoQueue, socket)) {
				descriptor_ref(socket);
				priorityqueue_push(interface->fifoQueue, socket);
			}
			break;
		}
	}

	/* trigger a send if we are currently idle */
	if(!(interface->flags & NIF_SENDING)) {
		_networkinterface_scheduleNextSend(interface);
	}
}
TCPRetransmitTimerExpiredEvent* tcpretransmittimerexpired_new(TCP* tcp) {
	TCPRetransmitTimerExpiredEvent* event = g_new0(TCPRetransmitTimerExpiredEvent, 1);
	MAGIC_INIT(event);

	shadowevent_init(&(event->super), &tcpretransmittimerexpired_functions);
	descriptor_ref(tcp);
	event->tcp = tcp;

	return event;
}
예제 #4
0
void networkinterface_associate(NetworkInterface* interface, Socket* socket) {
	MAGIC_ASSERT(interface);

	gint key = socket_getAssociationKey(socket);

	/* make sure there is no collision */
	utility_assert(!networkinterface_isAssociated(interface, key));

	/* insert to our storage */
	g_hash_table_replace(interface->boundSockets, GINT_TO_POINTER(key), socket);
	descriptor_ref(socket);
}
예제 #5
0
파일: shd-epoll.c 프로젝트: icbaker/shadow
static EpollWatch* _epollwatch_new(Epoll* epoll, Descriptor* descriptor, struct epoll_event* event) {
	EpollWatch* watch = g_new0(EpollWatch, 1);
	MAGIC_INIT(watch);
	g_assert(event);

	/* ref it for the EpollWatch, which also covers the listener reference
	 * (which is freed below in _epollwatch_free) */
	descriptor_ref(descriptor);

	watch->listener = listener_new((CallbackFunc)epoll_descriptorStatusChanged, epoll, descriptor);
	watch->descriptor = descriptor;
	watch->event = *event;

	descriptor_addStatusListener(watch->descriptor, watch->listener);

	return watch;
}