9 #define INPUT_BUF_SIZE 256
10 #define MAX_NR_ARGS 100
23 static int forward(struct peerd *peer, struct peer_req *pr)
26 r = submit_peer_req(peer, pr);
28 printf("couldn't forward request");
34 static int complete_forwarded(struct peerd *peer, struct peer_req *pr)
36 struct xseg_request *req = pr->req;
38 // assert mio->src_portno != NoPort
39 if (req->state & XS_SERVED)
41 else if (req->state & XS_FAILED)
44 printf("invalid state\n");
50 int dispatch(struct peerd *peer, struct peer_req *pr, struct xseg_request *xreq)
52 struct xseg_request *req = pr->req;
53 if (req->state & (XS_SERVED | XS_FAILED)){
54 log_pr("completing", pr);
55 complete_forwarded(peer, pr);
58 log_pr("forwarding", pr);
64 int mpause(struct peerd *peer)
66 struct xseg *xseg = peer->xseg;
67 struct xseg_port *port = xseg_get_port(xseg, peer->portno);
71 xlock_acquire(&port->rq_lock, peer->portno);
72 xlock_acquire(&port->pq_lock, peer->portno);
76 int munpause(struct peerd *peer)
78 struct xseg *xseg = peer->xseg;
79 struct xseg_port *port = xseg_get_port(xseg, peer->portno);
83 xlock_release(&port->rq_lock);
84 xlock_release(&port->pq_lock);
88 struct peerd *main_peer;
93 struct peerd * peer = main_peer;
94 char buf[INPUT_BUF_SIZE];
97 unsigned int portno = NoPort, dstgw, srcgw;
100 printf("waitin next line\n");
101 if (fgets(buf, INPUT_BUF_SIZE, stdin)) {
102 nl = strchr(buf, '\n');
105 buf[INPUT_BUF_SIZE -1] = 0;
106 printf("got line input\n");
107 ret = sscanf(buf, "set srcgw %u %u", &portno, &srcgw);
109 printf("found setsrcgw\n");
110 xseg_set_srcgw(peer->xseg, (uint32_t) portno, (uint32_t) srcgw);
113 ret = sscanf(buf, "set dstgw %u %u", &portno, &dstgw);
115 printf("found set dstgw\n");
116 xseg_set_dstgw(peer->xseg, (uint32_t) portno, (uint32_t) dstgw);
119 ret = sscanf(buf, "getandset srcgw %u %u", &portno, &srcgw);
121 printf("found getand set srcgw\n");
122 xseg_getandset_srcgw(peer->xseg, (uint32_t) portno, (uint32_t) srcgw);
125 ret = sscanf(buf, "getandset dstgw %u %u", &portno, &dstgw);
127 printf("found getandset dstgw\n");
128 xseg_getandset_dstgw(peer->xseg, (uint32_t) portno, (uint32_t) dstgw);
131 ret = sscanf(buf, "pause %u", &portno);
133 printf("found pause\n");
137 ret = sscanf(buf, "unpause %u", &portno);
139 printf("found unpause\n");
149 int custom_peer_init(struct peerd *peer, int argc, char *argv[])
152 struct monitor_io *mio;
153 struct monitord *monitor;
155 monitor = malloc(sizeof(struct monitord));
158 peer->priv = monitor;
159 monitor->mon_portno = NoPort;
162 for (i = 0; i < peer->nr_ops; i++) {
163 mio = malloc(sizeof(struct monitor_io));
166 peer->peer_reqs[i].priv = mio;
167 mio->src_portno = NoPort;
170 for (i = 1; i < argc; i++) {
171 if (!strcmp(argv[i], "-mp") && (i + 1 < argc)) {
172 monitor->mon_portno = atoi(argv[i+1]);
179 peer->interactive_func = main_loop;