/** * Module initialization * * @return - */ static int __init kkc_test1_init(void) { int err = 0; minfo(INFO1, "Starting KKC test"); struct kkc_sock *new_sock = NULL; if (kkc_connect(&sock, "udp:192.168.0.3:5678")) minfo(ERR1, "Failed connecting to UDP, as expected, sock=%p", sock); if (kkc_connect(&sock, "tcp:192.168.0.3:5678")) minfo(ERR1, "Failed connecting to TCP, shouldn't fail..sock = %p", sock); else kkc_sock_put(sock); if (kkc_listen(&sock, "tcp:192.168.0.3:0")) { minfo(ERR1, "Failed listening on TCP, shouldn't fail.. sock=%p", sock); goto exit0; } minfo(INFO1, "Socket names-local: '%s', remote: '%s'", kkc_sock_getsockname2(sock), kkc_sock_getpeername2(sock)); /* Accept the first incoming connection */ if ((err = kkc_sock_accept(sock, &new_sock, KKC_SOCK_BLOCK)) < 0) { minfo(ERR1, "Accept terminated by with error code:%d",err); goto exit0; } minfo(INFO1, "Accepted incoming connection, terminating listening on: '%s'", kkc_sock_getsockname2(new_sock)); /* destroy the listening socket*/ kkc_sock_put(new_sock); exit0: return 0; }
/** * \<\<private\>\> Processes a TCMI message m. * The message is desposed afterwords. * * @param *self - pointer to this migration manager instance * @param *m - pointer to a message to be processed */ static void tcmi_ccnmigman_process_msg(struct tcmi_migman *self, struct tcmi_msg *m) { struct tcmi_msg *resp; int result_code = 0; int accepted; struct tcmi_authenticate_msg *auth_msg; struct tcmi_generic_user_msg *user_msg; /* struct tcmi_ccnmigman *self_ccn = TCMI_CCNMIGMAN(self); */ int err; mdbg(INFO4, "Processing message ID"); switch(tcmi_msg_id(m)) { case TCMI_AUTHENTICATE_MSG_ID: auth_msg = TCMI_AUTHENTICATE_MSG(m); minfo(INFO1, "Authentication message arrived."); // Inform director that the node was connected err = director_node_connected(kkc_sock_getpeername2(tcmi_migman_sock(self)), tcmi_migman_slot_index(self), tcmi_authenticate_msg_auth_data_size(auth_msg), tcmi_authenticate_msg_auth_data(auth_msg), &accepted); // The check for accept is performed only if the director responded, otherwise the call is ignored if ( !err && !accepted ) { minfo(ERR1, "Director rejected peer connection"); break; } self->pen_id = tcmi_authenticate_msg_pen_id(auth_msg); self->peer_arch_type = tcmi_authenticate_msg_arch(auth_msg); if ( !( resp = tcmi_authenticate_resp_msg_new_tx(tcmi_msg_req_id(m), self->ccn_id, ARCH_CURRENT, result_code, tcmi_ccnman_get_mount_params()) ) ) { mdbg(ERR3, "Error creating response message"); break; } if ((err = tcmi_msg_send_anonymous(resp, tcmi_migman_sock(self)))) { mdbg(ERR3, "Error sending response message %d", err); } tcmi_msg_put(resp); tcmi_migman_set_state(self, TCMI_MIGMAN_CONNECTED); wake_up(&(TCMI_CCNMIGMAN(self)->wq)); break; case TCMI_GENERIC_USER_MSG_ID: user_msg = TCMI_GENERIC_USER_MSG(m); minfo(INFO1, "User message arrived."); err = director_generic_user_message_recv(tcmi_generic_user_msg_node_id(user_msg), 1, tcmi_migman_slot_index(self), tcmi_generic_user_msg_user_data_size(user_msg), tcmi_generic_user_msg_user_data(user_msg)); if ( err ) { mdbg(ERR3, "Error in processing user message %d", err); } break; default: minfo(INFO1, "Unexpected message ID %x, no handler available.", tcmi_msg_id(m)); break; } /* release the message */ tcmi_msg_put(m); }