msgb->addrlen = peer_addrlen;
memcpy(msgb->head, buffer, len);
msgb->len = len;
-
- fwp_msg_header_pull(msgb, &code, &hid);
-
- if ((code == NEGOTIATE_REQUEST)||(code == NEGOTIATE_RESPONSE))
- fwp_msgq_enqueue(&msgq_neg_in, msgb);
- sem_post(sem_msq_in);
- else {
- printf("Error: not valid negotiate frame\n");
- fwp_msgb_free(msgb);
- }
}
out:
close(lsockfd_un);
return NULL;
}
+
+void* fwp_server_admctrl(void *arg)
+{
+ struct fwp_msgb *msgb;
+ /* should be invoked periodicaly */
+
+ fwp_adm_test(&ctable_negotiate);
+ while (fwp_ctable_get(&ctable_negotiate, &ctentry)) {
+ msgb = fwp_msgq_dequeue(&msgq_neg_out);
+ if (ctentry.contract.status == NEGOTIATED )
+ fwp_ctable_put(&ctable_accepted, &ctentry);
+
+ msgb->data = msgb->head;
+ fwp_msgb_put(msgb, sizeof(struct fwp_msg_header));
+ fwp_msg_contract_put(msgb, &ctentry.contract);
+
+ fwp_vres_send(vres_id, msgb);
+ };
+}
+
+void fwp_server_negotiate_request(unsigned int hid, struct fwp_msgb *msgb)
+{
+ struct fwp_ctable_entry ctentry;
+ struct fwp_contract cnt_req;
+
+ fwp_msg_contract_pull(msgb, &cnt_req);
+ memcpy(&ctentry.contract, &cnt_req, sizeof(cnt_req));
+ memcpy(&ctentry.saddr, &msgb->addr, sizeof(msgb->addrlen));
+ ctentry.addrlen = msgb->addrlen;
+
+ fwp_msgq_enqueue(&msgq_neg_out, msgb);
+ fwp_ctable_put(&ctable_negotiate, &ctentry);
+}
+
void* fwp_server_thread(void* arg)
{
struct fwp_ctable_entry ctentry;
struct fwp_msgb *msgb;
unsigned int code, hid;
+ struct fwp_msgb *msgb;
+ unsigned int code, hid;
+
while (1) {
- while ((msgb = fwp_msgq_dequeue(&msgq_neg_in))) {
- fwp_msg_header_pull(msgb, &code, &hid);
-
- /*if (h.code != NEGOTIATE_REQUEST)
- * printf("Error: Request frame expected\n");
- */
- fwp_msg_contract_pull(msgb, &cnt);
- memcpy(&ctentry.contract, &cnt, sizeof(cnt));
- memcpy(&ctentry.saddr, &msgb->addr,
- sizeof(msgb->addrlen));
- ctentry.addrlen = msgb->addrlen;
-
- fwp_ctable_put(&ctable_negotiate, &ctentry);
-
- fwp_msgq_enqueue(&msgq_neg_out, msgb);
- }
+ sem_wait(sem_msg_in);
+ msgb = fwp_msgq_dequeue(&msgq_neg_in);
+ if (!msgb)
+ continue;
- fwp_adm_test(&ctable_negotiate);
- while (fwp_ctable_get(&ctable_negotiate, &ctentry)) {
- msgb = fwp_msgq_dequeue(&msgq_neg_out);
- if (ctentry.contract.status == NEGOTIATED )
- fwp_ctable_put(&ctable_accepted, &ctentry);
-
- msgb->data = msgb->head;
- fwp_msgb_put(msgb, sizeof(struct fwp_msg_header));
- fwp_msg_contract_put(msgb, &ctentry.contract);
+ fwp_msg_header_pull(msgb, &code, &hid);
- fwp_vres_send(vres_id, msgb);
- };
+ switch (code) {
+ case FWP_NEGT_REQ:
+ fwp_server_negotiate_request(hid, msgb);
+ break;
+ case default:
+ printf("Invalid message\n.");
+ fwp_msgb_free(msgb);
+ }
}
}
fwp_vres_send(vres_id, msgb);
}
-int fwp_client negotiate_response(unsigned int hid, struct msgb *msgb)
+int fwp_client_negotiate_response(unsigned int hid, struct msgb *msgb)
{
struct fwp_ctable_entry ctentry;
struct fwp_contract cnt_res;
break;
case FWP_NEGT_RES:
- fwp_client negotiate_response(hid, msgb);
+ fwp_client_negotiate_response(hid, msgb);
break;
+
+ case default:
+ printf("Invalid message\n.");
+ fwp_msgb_free(msgb);
}
}
}
pthread_attr_t attr;
sem_init(&sem_msg_in, 0, 0);
+
+/* while ((opt = getopt(argc, argv, "B:b:c:g:j:o:s:T:")) != -1) {
+ switch (opt) {
+ case 'B':
+ opt_def_bandwidth = atoi(optarg);
+ break;
+
+*/
+
mode = FWP_SERVER;
pthread_attr_init(&attr);
rc = pthread_create(&rx_thread_id, &attr, fwp_rx_thread, (void*) NULL);
if ( mode == FWP_CLIENT )
rc = pthread_create(&client_thread_id, &attr, fwp_client_thread,
NULL);
-
+#if 0
+ fprintf(stderr, "\nWaiting for threads to finish\n");
+ /* Wait for all threads to finish */
+ for (i=0; i < nr_streams + AC_NUM; i++) {
+ sem_wait(&sem_thread_finished);
+ }
+
+#endif
return 0;
}