From: Michal Sojka Date: Wed, 27 May 2009 21:34:29 +0000 (+0200) Subject: Inet protocol sends HELLO as the first message after connect() X-Git-Url: https://rtime.felk.cvut.cz/gitweb/frescor/forb.git/commitdiff_plain/fe5aff627bf66d39c8f2bfdbeacf4dce17c0db7f Inet protocol sends HELLO as the first message after connect() This allows the receiver to know sender's listening address, which is different from the address of the connect()ed socket. Besides the address, also orb_id is sent, which makes debugging easier. It this approach is found successful, this functionality should be moved to iop.c and protocols should have new connect callback which will be called by iop if the peer was never contacted. --- diff --git a/src/Makefile.omk b/src/Makefile.omk index 9461a70..8876fcc 100644 --- a/src/Makefile.omk +++ b/src/Makefile.omk @@ -40,6 +40,7 @@ renamed_include_HEADERS += \ $(call to_forb_subdir, request.h) \ $(call to_forb_subdir, syncobj.h) \ $(call to_forb_subdir, server_id.h) \ + $(call to_forb_subdir, peer.h) \ $(call to_forb_subdir, uuid.h) renamed_include_GEN_HEADERS = \ diff --git a/src/iop.c b/src/iop.c index f6dca49..74d817c 100644 --- a/src/iop.c +++ b/src/iop.c @@ -131,6 +131,32 @@ forb_iop_prepare_hello(FORB_CDR_Codec *codec, return CORBA_TRUE; } +int forb_iop_send_hello_to(forb_peer_t *peer) +{ + forb_port_t *port = peer->port; + FORB_CDR_Codec codec; + int ret; + FORB_CDR_codec_init_static(&codec, port->forb->orb); + if (!FORB_CDR_buffer_init(&codec, 1024, 0)) + return -1; + if (!FORB_CDR_buffer_reset(&codec, forb_iop_MESSAGE_HEADER_SIZE)) { + ret = -1; + goto free; + } + if (!forb_iop_prepare_hello(&codec, &port->forb->server_id, + port->desc.addr, + port->desc.proto->serialize_addr, + port->forb->attr.orb_id)) { + ret = -1; + goto free; + } + ret = forb_proto_send(peer, &codec); + if (ret > 0) ret = 0; +free: + FORB_CDR_codec_release_buffer(&codec); + return ret; +} + bool forb_iop_process_message_header(forb_iop_message_header *mh, FORB_CDR_Codec *codec) { @@ -451,6 +477,13 @@ process_hello(forb_port_t *port, FORB_CDR_Codec *codec) forb_free(peer_orb_id); forb_peer_put(peer); } else { + if (port->new_peer) { + if (peer) + ul_logerr("Unahandled case - FORB_PEER_WANTED && port->new_peer\n"); + peer = port->new_peer; + port->new_peer = NULL; + } + forb_new_peer_discovered(port, peer, server_id, addr, peer_orb_id); } } diff --git a/src/iop.h b/src/iop.h index 4dc764c..38971f6 100644 --- a/src/iop.h +++ b/src/iop.h @@ -60,6 +60,7 @@ #include #include #include +#include CORBA_boolean forb_iop_prepend_message_header(FORB_CDR_Codec *codec, forb_iop_message_type mt); @@ -92,4 +93,7 @@ forb_iop_discovery_thread(void *arg); void forb_request_send(forb_request_t *req, CORBA_Environment *env); +int +forb_iop_send_hello_to(forb_peer_t *peer); + #endif diff --git a/src/proto_inet.c b/src/proto_inet.c index 3281aed..5cef70d 100644 --- a/src/proto_inet.c +++ b/src/proto_inet.c @@ -60,6 +60,7 @@ #include #include #include "discovery.h" +#include "iop.h" /* FIXME: Sending hello should be handled in IOP layer */ /** * @file proto_inet.c @@ -145,7 +146,7 @@ inet_deserialize_addr(FORB_CDR_Codec *codec, void **addr) return ret; } -static struct inet_peer * +static int inet_connect(forb_peer_t *peer) { struct inet_peer *ipeer; @@ -155,7 +156,7 @@ inet_connect(forb_peer_t *peer) if (!addr) { ul_logerr("No address to connect\n"); - return NULL; + goto err; } ipeer = forb_malloc(sizeof(*ipeer)); if (!ipeer) @@ -186,14 +187,22 @@ inet_connect(forb_peer_t *peer) goto err_close; } + peer->proto_priv = ipeer; + +#ifndef TEST /* FIXME: Move hello to IOP, introduce proto connect callback */ + ret = forb_iop_send_hello_to(peer); + if (ret) { + goto err_close; + } +#endif - return ipeer; + return 0; err_close: close(ipeer->socket); err_free: forb_free(ipeer); err: - return NULL; + return -1; } @@ -204,12 +213,11 @@ inet_send(forb_peer_t *peer, const void *buf, size_t len) ssize_t ret, sent; if (!ipeer) { - ipeer = inet_connect(peer); - if (!ipeer) { - return -1; + ret = inet_connect(peer); + if (ret) { + return ret; } - peer->proto_priv = ipeer; - + ipeer = peer->proto_priv; } sent = 0; @@ -287,7 +295,6 @@ inet_accept_connection(forb_port_t *port) peer->port = port; peer->state = FORB_PEER_DISCOVERED; inet_port_new_peer_insert(p, peer); - //printf("New connection d=%d\n", client); } else { forb_peer_put(peer); }