- char * force = GNUNET_malloc(30);
- if (force_address == GNUNET_YES)
- strcpy(force,"forced addr.");
- if (force_address == GNUNET_NO)
- strcpy(force,"any addr.");
- if (force_address == GNUNET_SYSERR)
- strcpy(force,"reliable bi-direc. address addr.");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Transport tells me to send %u bytes to `%s' %s (%s), session: %X\n",
- msgbuf_size,
- GNUNET_i2s(&pc->identity),
- force,
- http_plugin_address_to_string(NULL, addr, addrlen),
- ps);
+ /* session not existing, but address forced -> creating new session */
+ if ((ps==NULL) || ((ps==NULL) && (force_address == GNUNET_YES)))
+ {
+ if ((addr!=NULL) && (addrlen!=0))
+ {
+ if (force_address == GNUNET_YES)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No existing connection & forced address: creating new connection to peer %s\n", GNUNET_i2s(target));
+ if (force_address != GNUNET_YES)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No existing connection: creating new connection to peer %s\n", GNUNET_i2s(target));
+
+ ps = GNUNET_malloc(sizeof (struct Session));
+ if ((addrlen!=0) && (addr!=NULL))
+ {
+ ps->addr = GNUNET_malloc(addrlen);
+ memcpy(ps->addr,addr,addrlen);
+ ps->addrlen = addrlen;
+ }
+ else
+ {
+ ps->addr = NULL;
+ ps->addrlen = 0;
+ }
+ ps->direction=OUTBOUND;
+ ps->recv_connected = GNUNET_NO;
+ ps->recv_force_disconnect = GNUNET_NO;
+ ps->send_connected = GNUNET_NO;
+ ps->send_force_disconnect = GNUNET_NO;
+ ps->pending_msgs_head = NULL;
+ ps->pending_msgs_tail = NULL;
+ ps->peercontext=pc;
+ ps->session_id = pc->session_id_counter;
+ pc->session_id_counter++;
+ ps->url = create_url (plugin, ps->addr, ps->addrlen, ps->session_id);
+ if (ps->msgtok == NULL)
+ ps->msgtok = GNUNET_SERVER_mst_create (&curl_receive_mst_cb, ps);
+ GNUNET_CONTAINER_DLL_insert(pc->head,pc->tail,ps);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No existing session & and no address given: no way to send this message to peer `%s'!\n", GNUNET_i2s(target));
+ return -1;
+ }
+ }