+ et = ntohs (em->type);
+ for (hpos = 0; hpos < h->hcnt; hpos++)
+ {
+ mh = &h->handlers[hpos];
+ if (mh->type != et)
+ continue;
+ if ((mh->expected_size != ntohs (em->size)) && (mh->expected_size != 0))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected message size %u for message of type %u from peer `%4s'\n",
+ htons (em->size), mh->type, GNUNET_i2s (&ntm->peer));
+ GNUNET_break_op (0);
+ continue;
+ }
+ if (GNUNET_OK !=
+ h->handlers[hpos].callback (h->cls, &ntm->peer, em, &ntm->ats,
+ ats_count))
+ {
+ /* error in processing, do not process other messages! */
+ break;
+ }
+ }
+ if (NULL != h->inbound_notify)
+ h->inbound_notify (h->cls, &ntm->peer, em, &ntm->ats, ats_count);
+ break;
+ case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND:
+ if (msize < sizeof (struct NotifyTrafficMessage))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ ntm = (const struct NotifyTrafficMessage *) msg;
+ if (0 == memcmp (&h->me, &ntm->peer, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* self-change!? */
+ GNUNET_break (0);
+ return;
+ }
+ ats_count = ntohl (ntm->ats_count);
+ if ((msize <
+ sizeof (struct NotifyTrafficMessage) +
+ ats_count * sizeof (struct GNUNET_ATS_Information) +
+ sizeof (struct GNUNET_MessageHeader)) ||
+ (GNUNET_ATS_ARRAY_TERMINATOR != ntohl ((&ntm->ats)[ats_count].type)))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ em = (const struct GNUNET_MessageHeader *) &(&ntm->ats)[ats_count + 1];
+ pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &ntm->peer.hashPubKey);
+ if (pr == NULL)
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+#if DEBUG_CORE
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received notification about transmission to `%s'.\n",
+ GNUNET_i2s (&ntm->peer));
+#endif
+ if ((GNUNET_NO == h->outbound_hdr_only) &&
+ (msize !=
+ ntohs (em->size) + sizeof (struct NotifyTrafficMessage) +
+ ats_count * sizeof (struct GNUNET_ATS_Information)))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ if (NULL == h->outbound_notify)
+ {
+ GNUNET_break (0);
+ break;
+ }
+ h->outbound_notify (h->cls, &ntm->peer, em, &ntm->ats, ats_count);
+ break;
+ case GNUNET_MESSAGE_TYPE_CORE_SEND_READY:
+ if (msize != sizeof (struct SendMessageReady))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ smr = (const struct SendMessageReady *) msg;
+ pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &smr->peer.hashPubKey);
+ if (pr == NULL)
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+#if DEBUG_CORE
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received notification about transmission readiness to `%s'.\n",
+ GNUNET_i2s (&smr->peer));
+#endif
+ if (pr->pending_head == NULL)
+ {
+ /* request must have been cancelled between the original request
+ * and the response from core, ignore core's readiness */
+ break;
+ }
+
+ th = pr->pending_head;
+ if (ntohs (smr->smr_id) != th->smr_id)
+ {
+ /* READY message is for expired or cancelled message,
+ * ignore! (we should have already sent another request) */
+ break;
+ }
+ if ((pr->prev != NULL) || (pr->next != NULL) || (h->ready_peer_head == pr))
+ {
+ /* we should not already be on the ready list... */
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ GNUNET_CONTAINER_DLL_insert (h->ready_peer_head, h->ready_peer_tail, pr);
+ trigger_next_request (h, GNUNET_NO);
+ break;
+ default:
+ reconnect_later (h);
+ return;
+ }
+ GNUNET_CLIENT_receive (h->client, &main_notify_handler, h,
+ GNUNET_TIME_UNIT_FOREVER_REL);