Example #1
0
/**
 * This is the tunnel interface send function.
 */
static int _ipip_iface_send(net_iface_t * self,
			    net_addr_t next_hop,
			    net_msg_t * msg)
{
  ipip_data_t * ctx= (ipip_data_t *) self->user_data;
  net_addr_t src_addr= ctx->src_addr;
  net_msg_t * outer_msg;

  ___ipip_debug("_ipip_iface_send msg=%m\n", msg);

  if (ctx->oif != NULL) {
    // Default IP encap source address = outgoing interface's address.
    if (src_addr == NET_ADDR_ANY)
	src_addr= ctx->oif->addr;

    //TO BE WRITTEN: return node_ip_output(); ...
    return EUNSUPPORTED;

  } else {

    outer_msg= message_create(src_addr, self->dest.end_point,
			      NET_PROTOCOL_IPIP, 255, msg,
			      _ipip_msg_destroy);

    ip_opt_hook_msg_encap(self->owner, outer_msg, msg);

    node_send(self->owner, outer_msg, NULL, NULL);
    return ESUCCESS;
  }
}
Example #2
0
int distribute_thr(int recvSock)
{
    char *p, buf[2048], *url;
    URLNODE_T *urlNode;

    urlNode = (URLNODE_T *) buf;
    url = buf + sizeof(URLNODE_T);

    while (1)
    {
        node_recv(recvSock, buf, 2048);
        assert(urlNode->urlLen + sizeof(URLNODE_T) < 2048);

        *(url + urlNode->urlLen) = 0;
        printf("recv: %s urlLen: %d", url, urlNode->urlLen);

        if (link_filter(url) == 0)
            continue;

        node_send(urlNode, url);
        printf("send (%s) to center\n", links->links[i]);
    }

    return 0;
}
Example #3
0
void node_send_init(void *dummy) {
    json_t *plugin_paths = json_array();
    json_array_append_new(plugin_paths, json_string(os_bundled_resources_path));

    json_t *data = json_object();
    json_object_set_new(data, "pluginFolders", plugin_paths);
    json_object_set_new(data, "preferencesFolder", json_string(os_preferences_path));
    json_object_set_new(data, "version", json_string(LIVERELOAD_VERSION));

    node_send("app.init", data);
}
Example #4
0
File: node.c Project: ageric/merlin
/*
 * Send the given event "pkt" to the node "node", or take appropriate
 * actions on the node itself in case sending fails.
 * Returns 0 on success, and < 0 otherwise.
 */
int node_send_event(merlin_node *node, merlin_event *pkt, int msec)
{
	int result;

	node_log_event_count(node, 0);

	if (packet_size(pkt) > TOTAL_PKT_SIZE) {
		lerr("header is invalid, or packet is too large. aborting");
		return -1;
	}

	if (node->sock < 0 || node->state != STATE_CONNECTED) {
		return node_binlog_add(node, pkt);
	}

	/*
	 * msec less than zero means the caller has already polled the
	 * socket, which should also mean it's connected
	 */
	if (msec >= 0 && !io_write_ok(node->sock, msec)) {
		return node_binlog_add(node, pkt);
	}

	if (is_module && is_stalling()) {
		return node_binlog_add(node, pkt);
	}

	/* if binlog has entries, we must send those first */
	if (binlog_has_entries(node->binlog)) {
		node_send_binlog(node, pkt);
	}

	/* binlog may still have entries. If so, add to it and return */
	if (binlog_has_entries(node->binlog))
		return node_binlog_add(node, pkt);

	result = node_send(node, pkt, packet_size(pkt), MSG_DONTWAIT);

	/* successfully sent, so add it to the counter and return 0 */
	if (result == packet_size(pkt)) {
		node->stats.events.sent++;
		return 0;
	}

	/*
	 * zero size writes and write errors get stashed in binlog.
	 * From the callers point of view, this counts as a success.
	 */
	if (result <= 0 && !node_binlog_add(node, pkt))
		return 0;

	/* node_send will have marked the node as out of sync now */
	return -1;
}
Example #5
0
void S_app_ping(json_t *data) {
    node_send("app.ping", data);
}
Example #6
0
void S_app_init(json_t *data) {
    node_send("app.init", data);
}
Example #7
0
void S_websockets_send_reload_command(json_t *data) {
    node_send("websockets.sendReloadCommand", data);
}
Example #8
0
void S_projects_change_detected(json_t *data) {
    node_send("projects.changeDetected", data);
}
Example #9
0
void S_projects_remove(json_t *data) {
    node_send("projects.remove", data);
}
Example #10
0
void S_projects_add(json_t *data) {
    node_send("projects.add", data);
}
Example #11
0
File: node.c Project: ageric/merlin
int node_send_binlog(merlin_node *node, merlin_event *pkt)
{
	merlin_event *temp_pkt;
	uint len;

	ldebug("Emptying backlog for %s", node->name);
	while (io_write_ok(node->sock, 10) && !binlog_read(node->binlog, (void **)&temp_pkt, &len)) {
		int result;
		if (!temp_pkt || packet_size(temp_pkt) != (int)len ||
		    !len || !packet_size(temp_pkt) || packet_size(temp_pkt) > MAX_PKT_SIZE)
		{
			if (!temp_pkt) {
				lerr("BACKLOG: binlog returned 0 but presented no data");
			} else {
				lerr("BACKLOG: binlog returned a packet claiming to be of size %d", packet_size(temp_pkt));
			}
			lerr("BACKLOG: binlog claims the data length is %u", len);
			lerr("BACKLOG: wiping backlog. %s is now out of sync", node->name);
			binlog_wipe(node->binlog, BINLOG_UNLINK);
			return -1;
		}
		errno = 0;
		result = node_send(node, temp_pkt, packet_size(temp_pkt), MSG_DONTWAIT);

		/* keep going while we successfully send something */
		if (result == packet_size(temp_pkt)) {
			node->stats.events.sent++;
			node->stats.events.logged--;
			node->stats.bytes.logged -= packet_size(temp_pkt);

			/*
			 * binlog duplicates the memory, so we must release it
			 * when we've sent and counted it
			 */
			free(temp_pkt);
			continue;
		}

		/*
		 * we can recover from total failures by unread()'ing
		 * the entry we just read and then adding the new entry
		 * to the binlog in the hopes that we'll get a
		 * connection up and running again before it's time to
		 * send more data to this node
		 */
		if (result <= 0) {
			if (!binlog_unread(node->binlog, temp_pkt, len)) {
				if (pkt)
					return node_binlog_add(node, pkt);
				return 0;
			} else {
				free(temp_pkt);
			}
		}

		/*
		 * we wrote a partial event or failed to unread the event,
		 * so this node is now out of sync. We must wipe the binlog
		 * and possibly mark this node as being out of sync.
		 */
		lerr("Wiping binlog for %s node %s", node_type(node), node->name);
		binlog_wipe(node->binlog, BINLOG_UNLINK);
		if (pkt) {
			node->stats.events.dropped += node->stats.events.logged + 1;
			node->stats.bytes.dropped += node->stats.bytes.logged + packet_size(pkt);
		}
		node_log_event_count(node, 0);
		return -1;
	}

	return 0;
}