Esempio n. 1
0
int cnt_event_handler(void *nul, struct Simulator *aSim, struct CntEvent *aCntEvent)
{
	int rt;
	struct Node *aNode, *bNode;

	
	aNode = lookup_node(&aSim->vnodes, aCntEvent->name1);
	bNode = lookup_node(&aSim->vnodes, aCntEvent->name2);

	if(aSim->oracle->type == TYPE_ORACLE_MARKOV) 
		rt = process_markov_cnt_event(aSim, aNode, bNode, aCntEvent);
	else if(aSim->oracle->type == TYPE_ORACLE_AVGDLY) 
		rt = process_avgdly_cnt_event(aSim, aNode, bNode, aCntEvent);
	else if(aSim->oracle->type == TYPE_ORACLE_AVGPRB) 
		rt = process_avgprb_cnt_event(aSim, aNode, bNode, aCntEvent);
	else if(aSim->oracle->type == TYPE_ORACLE_EPIDEMIC) 
		rt = process_epidemic_cnt_event(aSim, aNode, bNode);
	else if(aSim->oracle->type == TYPE_ORACLE_BUBBLE) 
		rt = process_bubble_cnt_event(aSim, aNode, bNode);
	else if(aSim->oracle->type == TYPE_ORACLE_SIMBET) 
		rt = process_simbet_cnt_event(aSim, aNode, bNode, aCntEvent);
	else if(aSim->oracle->type == TYPE_ORACLE_SOCIAL) 
		rt = process_social_cnt_event(aSim, aNode, bNode, aCntEvent);

	free(aCntEvent);
	return rt;
}
Esempio n. 2
0
// Joins the thread with the calling thread
void mythread_join(int thread_id)
{
	// Wait for timer the first time
	int i;
	while (running_thread[1] == NULL)
		for (i = 0 ; i < MAX; i++);
	int joined = FALSE;
	Node *temp = -1;
	temp = lookup_node(thread_id, READY);
	TCB *tcb;
	int calling_id = running_thread[1]->thread.thread_id;
	alt_printf("Joining if not finished.\n");

	temp = lookup_node(thread_id, READY);
	if (temp != 0xffffffff)
		tcb = &temp->thread;
	if (temp != 0xffffffff && tcb->scheduling_status != DONE){
		// Join the thread
		tcb->blocking_id = calling_id;
		running_thread[1]->thread.scheduling_status = WAITING;
		joined = TRUE;
	}

	if (joined == TRUE)
		alt_printf("Joined (%x)\n", thread_id);
	// Wait for timer
	while (running_thread[1]->thread.scheduling_status == WAITING)
		for (i = 0 ; i < MAX; i++);
}
Esempio n. 3
0
bool req_key_h(connection_t *c) {
	char from_name[MAX_STRING_SIZE];
	char to_name[MAX_STRING_SIZE];
	node_t *from, *to;

	if(sscanf(c->buffer, "%*d " MAX_STRING " " MAX_STRING, from_name, to_name) != 2) {
		logger(LOG_ERR, "Got bad %s from %s (%s)", "REQ_KEY", c->name,
			   c->hostname);
		return false;
	}

	if(!check_id(from_name) || !check_id(to_name)) {
		logger(LOG_ERR, "Got bad %s from %s (%s): %s", "REQ_KEY", c->name, c->hostname, "invalid name");
		return false;
	}

	from = lookup_node(from_name);

	if(!from) {
		logger(LOG_ERR, "Got %s from %s (%s) origin %s which does not exist in our connection list",
			   "REQ_KEY", c->name, c->hostname, from_name);
		return true;
	}

	to = lookup_node(to_name);

	if(!to) {
		logger(LOG_ERR, "Got %s from %s (%s) destination %s which does not exist in our connection list",
			   "REQ_KEY", c->name, c->hostname, to_name);
		return true;
	}

	/* Check if this key request is for us */

	if(to == myself) {			/* Yes, send our own key back */
		if (!send_ans_key(from))
			return false;
	} else {
		if(tunnelserver)
			return true;

		if(!to->status.reachable) {
			logger(LOG_WARNING, "Got %s from %s (%s) destination %s which is not reachable",
				"REQ_KEY", c->name, c->hostname, to_name);
			return true;
		}

		send_request(to->nexthop->connection, "%s", c->buffer);
	}

	return true;
}
Esempio n. 4
0
// Threads return here and space is freed
void mythread_cleanup()
{
	// Unblock thread blocked by join
	DISABLE_INTERRUPTS();
	int id = running_thread[1]->thread.blocking_id;
	if (id > 0) {
		Node * temp = 0xffffffff;
		temp = lookup_node(running_thread[1]->thread.blocking_id, WAITING); //Blocking ID was not the expected value Camtendo 11/4
		if (temp != 0xffffffff) // not found
		{
			Node * blocked_node = (Node *) malloc(sizeof(Node));
			blocked_node->thread = temp->thread;
			blocked_node->thread.scheduling_status = READY;
			remove_node(temp, WAITING);
			add_node(blocked_node, READY);
		}
	}
	ENABLE_INTERRUPTS();
	alt_printf("COMPLETED.\n");
	DISABLE_INTERRUPTS();
	free(running_thread[1]->thread.context);
	running_thread[1]->thread.scheduling_status = DONE;
	ENABLE_INTERRUPTS();
	while(TRUE);
}
Esempio n. 5
0
void load_all_nodes(meshlink_handle_t *mesh) {
	DIR *dir;
	struct dirent *ent;
	char dname[PATH_MAX];

	snprintf(dname,PATH_MAX, "%s" SLASH "hosts", mesh->confbase);
	dir = opendir(dname);
	if(!dir) {
		logger(mesh, MESHLINK_ERROR, "Could not open %s: %s", dname, strerror(errno));
		return;
	}

	while((ent = readdir(dir))) {
		if(!check_id(ent->d_name))
			continue;

		node_t *n = lookup_node(mesh, ent->d_name);
		if(n)
			continue;

		n = new_node();
		n->name = xstrdup(ent->d_name);
		node_read_devclass(mesh, n);
		node_add(mesh, n);
	}

	closedir(dir);
}
Esempio n. 6
0
void rbtree_delete(rbtree t, void* key, compare_func compare) {
    node child;
    node n = lookup_node(t, key, compare);
    if (n == NULL) return;  /* Key not found, do nothing */
    if (n->left != NULL && n->right != NULL) {
        /* Copy key/value from predecessor and then delete it instead */
        node pred = maximum_node(n->left);
        n->key   = pred->key;
        n->value = pred->value;
        n = pred;
    }

    assert(n->left == NULL || n->right == NULL);
    child = n->right == NULL ? n->left  : n->right;
    if (node_color(n) == BLACK) {
        n->color = node_color(child);
        delete_case1(t, n);
    }
    replace_node(t, n, child);
    if (n->parent == NULL && child != NULL)
        child->color = BLACK;
    free(n);

    verify_properties(t);
}
Esempio n. 7
0
device_t register_device(const char *name)
{
    PLIST link = NULL;
    DEVCONTEXT context;
    PDEVCONTEXT pContext;
    device_t devHdl = 0;
    link = lookup_node(device_list,(void *)name,MEMBER_OFF(DEVCONTEXT,so_name),strlen(name) + 1);
    if(!link)
    {
        strncpy(context.so_name,name,SONAMELEN);
        if((devHdl = register_device_ex(&context)) > 0)
        {
            if(context.device_open && context.device_open() >= 0)
            {
                link = list_add(device_list,&context);
            }
            if(link)
            {
                pContext = (PDEVCONTEXT)link->data;
                pthread_create(&pContext->threadHdl,NULL,device_thread,(void *)pContext);
                return devHdl;
            }
        }
    }
    return 0;
}
Esempio n. 8
0
void rbtree_delete(GtkWidget *darea, rbtree t, int key) {
  node n = lookup_node(darea, t, key);
  node child;

  if (n == NULL) return;

  if (n->left != NULL && n->right != NULL) {
    node pred = maximum_node(n->left);

    n->key   = pred->key;
    n = pred;
  }

  child = n->right == NULL ? n->left : n->right;
  if (node_color(n) == BLACK) {
    n->color = node_color(child);

    delete_case1(darea, t, n);
  }

  replace_node(t, n, child);

  if (n->parent == NULL && child != NULL)
    child->color = BLACK;

  free(n);
}
Esempio n. 9
0
File: node.c Progetto: tonyg/hop
int send_node(cmsg_bytes_t node, sexp_t *message) {
  node_t *n = lookup_node(node);
  if (n == NULL) {
    return 0;
  }
  n->node_class->handle_message(n, message);
  return 1;
}
Esempio n. 10
0
/*
  Read Subnets from all host config files
*/
void load_all_subnets(void) {
    DIR *dir;
    struct dirent *ent;
    char *dname;
    char *fname;
    avl_tree_t *config_tree;
    config_t *cfg;
    subnet_t *s, *s2;
    node_t *n;
    bool result;

    xasprintf(&dname, "%s/hosts", confbase);
    dir = opendir(dname);
    if(!dir) {
        logger(LOG_ERR, "Could not open %s: %s", dname, strerror(errno));
        free(dname);
        return;
    }

    while((ent = readdir(dir))) {
        if(!check_id(ent->d_name))
            continue;

        n = lookup_node(ent->d_name);
#ifdef _DIRENT_HAVE_D_TYPE
        //if(ent->d_type != DT_REG)
        //	continue;
#endif

        xasprintf(&fname, "%s/hosts/%s", confbase, ent->d_name);
        init_configuration(&config_tree);
        result = read_config_file(config_tree, fname);
        free(fname);
        if(!result)
            continue;

        if(!n) {
            n = new_node();
            n->name = xstrdup(ent->d_name);
            node_add(n);
        }

        for(cfg = lookup_config(config_tree, "Subnet"); cfg; cfg = lookup_config_next(config_tree, cfg)) {
            if(!get_config_subnet(cfg, &s))
                continue;

            if((s2 = lookup_subnet(n, s))) {
                s2->expires = -1;
            } else {
                subnet_add(n, s);
            }
        }

        exit_configuration(&config_tree);
    }

    closedir(dir);
}
Esempio n. 11
0
 V* get(K const& key) const {
     unsigned hv = HASH(key);
     Node const** ptr = lookup_node(hv, key);
     if (*ptr != NULL) {
         return const_cast<V*>(&(*ptr)->_value);
     } else {
         return NULL;
     }
 }
Esempio n. 12
0
int unregister_device(device_t hdl)
{
    PLIST plink = NULL;
    int ret = -1;
    plink = lookup_node(device_list,(void *)&hdl,MEMBER_OFF(DEVCONTEXT,sohdl),sizeof(hdl));
    if(plink)
    {
        ret = unregister_device_ex(plink);
    }
    return ret;
}
Esempio n. 13
0
 /**
  * Inserts or replaces a value in the table.
  * @return: true:  if a new item is added
  *          false: if the item already existed and the value is updated
  */
 bool put(K const& key, V const& value) {
     unsigned hv = HASH(key);
     Node** ptr = lookup_node(hv, key);
     if (*ptr != NULL) {
         (*ptr)->_value = value;
         return false;
     } else {
         *ptr = new Node(hv, key, value);
         return true;
     }
 }
Esempio n. 14
0
/*
 *  l_rbtreeLookup()
 *
 *      Input:  t (rbtree, including root node)
 *              key (find a node with this key)
 *      Return: &value (a pointer to a union, if the node exists; else NULL)
 */
RB_TYPE *
l_rbtreeLookup(L_RBTREE  *t,
               RB_TYPE    key)
{
    PROCNAME("l_rbtreeLookup");

    if (!t)
        return (RB_TYPE *)ERROR_PTR("tree is null\n", procName, NULL);

    node *n = lookup_node(t, key);
    return n == NULL ? NULL : &n->value;
}
Esempio n. 15
0
ALWAYS_INLINE void *
lwan_trie_lookup_full(struct lwan_trie *trie, const char *key, bool prefix)
{
    if (UNLIKELY(!trie))
        return NULL;

    size_t prefix_len;
    struct lwan_trie_node *node = lookup_node(trie->root, key, prefix, &prefix_len);
    if (!node)
        return NULL;
    struct lwan_trie_leaf *leaf = find_leaf_with_key(node, key, prefix_len);
    return leaf ? leaf->data : NULL;
}
Esempio n. 16
0
int
nnpfs_pioctl_call(d_thread_t *proc,
		struct sys_pioctl_args *arg,
		register_t *return_value)
{
    int error;
    struct ViceIoctl vice_ioctl;
    char *pathptr;
    struct vnode *vp = NULL;

    NNPFSDEB(XDEBSYS, ("nnpfs_syscall(%d, %lx, %d, %lx, %d)\n", 
		     SCARG(arg, operation),
		     (unsigned long)SCARG(arg, a_pathP),
		     SCARG(arg, a_opcode),
		     (unsigned long)SCARG(arg, a_paramsP),
		     SCARG(arg, a_followSymlinks)));

    /* Copy in the data structure for us */

    error = copyin(SCARG(arg, a_paramsP),
		   &vice_ioctl,
		   sizeof(vice_ioctl));

    if (error)
	return error;

    pathptr = SCARG(arg, a_pathP);

    if (pathptr != NULL) {
	error = lookup_node (pathptr, SCARG(arg, a_followSymlinks), &vp,
			     proc);
	if(error)
	    return error;
    }
	
    switch (SCARG(arg, a_opcode)) {
    case VIOC_FHGET :
	return fhget_call (proc, &vice_ioctl, vp);
    case VIOC_FHOPEN :
	return fhopen_call (proc, &vice_ioctl, vp,
			    SCARG(arg, a_followSymlinks), return_value);
    case VIOC_NNPFSDEBUG :
	if (vp != NULL)
	    vrele (vp);
	return nnpfs_debug (proc, &vice_ioctl);
    default :
	NNPFSDEB(XDEBSYS, ("a_opcode = %x\n", SCARG(arg, a_opcode)));
	return remote_pioctl (proc, arg, &vice_ioctl, vp);
    }
}
Esempio n. 17
0
static int dev_ioctl(PDEVMSG pMsg)
{
    int ret = -1;
    PLIST plink = NULL; 
    PDEVCONTEXT pContext = NULL;
    plink = lookup_node(device_list,(void *)&pMsg->sohdl,MEMBER_OFF(DEVCONTEXT,sohdl),sizeof(pMsg->sohdl));
    if(plink)
    {
        pContext = (PDEVCONTEXT)plink->data;
        if(pContext->device_ctl)
            ret = pContext->device_ctl(pMsg->cmd,pMsg->param);
    }
    return ret;
}
Esempio n. 18
0
bool read_edges(char* edgesPath) {
	extern edge* edges;
	extern int edgesCount;

	char name1[MAX_LINE_LENGTH];
	char name2[MAX_LINE_LENGTH];
	char names[MAX_LINE_LENGTH];
	int idx1;
	int idx2;
	float weight;
	bool success = TRUE;
	FILE * fp;

	/* open file */
	fp = fopen(edgesPath, "r");
	if (fp == NULL) {
		perror("Error: Input file not readable.\n");
		return FALSE;
	}

	/* figure out number of edges in file */
	file_lines_count(fp, &edgesCount);

	/* allocate memory for edges array */
	edges = calloc(sizeof(edge), edgesCount);

	/* Loop through lines, adding nodes */
	while (success && (fscanf(fp, "interaction: %s %f", names, &weight) == 2)) {
		success = split_names(names, name1, name2);
		if (success && lookup_node(name1, &idx1) && lookup_node(name2, &idx2)) {
			success = add_edge(idx1, idx2, weight);
		}
		fscanf(fp, "\n");
	}

	return success;
}
Esempio n. 19
0
/*
 * is_dir must be -1 (don't care), 0 (not a dir) or NODE_FLAG_IS_DIR.
 *
 * if (op != GFARM_INODE_CREATE), (is_dir) may be -1,
 * and that means "don't care".
 */
static char *
lookup_relative(struct node *n, const char *path, int is_dir,
	enum gfarm_node_lookup_op op, struct node **np)
{
	char *e;
	int len;

	if ((n->flags & NODE_FLAG_IS_DIR) == 0)
		return (GFARM_ERR_NOT_A_DIRECTORY);
	for (;;) {
		while (*path == '/')
			path++;
		for (len = 0; path[len] != '/'; len++) {
			if (path[len] == '\0') {
				e = lookup_node(n, path, len, is_dir, op, &n);
				if (e != NULL)
					return (e);
				if (is_dir != -1 &&
				    (n->flags & NODE_FLAG_IS_DIR) != is_dir)
					return ((n->flags & NODE_FLAG_IS_DIR) ?
					    GFARM_ERR_IS_A_DIRECTORY :
					    GFARM_ERR_NOT_A_DIRECTORY);
				if (np != NULL)
					*np = n;
				return (NULL);
			}
		}
		e = lookup_node(n, path, len, NODE_FLAG_IS_DIR,
		    op == GFARM_INODE_MARK ?
		    GFARM_INODE_MARK : GFARM_INODE_LOOKUP, &n);
		if (e != NULL)
			return (e);
		if ((n->flags & NODE_FLAG_IS_DIR) == 0)
			return (GFARM_ERR_NOT_A_DIRECTORY);
		path += len;
	}
}
Esempio n. 20
0
void route(meshlink_handle_t *mesh, node_t *source, vpn_packet_t *packet) {
	// TODO: route on name or key

	node_t *owner = NULL;
	node_t *via = NULL;
	meshlink_packethdr_t *hdr = (meshlink_packethdr_t *) packet->data;
	owner = lookup_node(mesh, (char *)hdr->destination);
	logger(mesh, MESHLINK_DEBUG, "Routing packet from \"%s\" to \"%s\"\n", hdr->source, hdr->destination);

	//Check Lenght
	if(!checklength(source, packet, sizeof *hdr))
		return;

	if(owner == NULL) {
		//Lookup failed
		logger(mesh, MESHLINK_WARNING, "Cant lookup the owner of a packet in the route() function. This should never happen!\n");
		logger(mesh, MESHLINK_WARNING, "Destination was: %s\n", hdr->destination);
		return;
	}

	if(owner == mesh->self) {
		const void *payload = packet->data + sizeof *hdr;
		size_t len = packet->len - sizeof *hdr;

		char hex[len*2 + 1];
		if(mesh->log_level >= MESHLINK_DEBUG)
			bin2hex(payload, hex, len);	// don't do this unless it's going to be logged
		logger(mesh, MESHLINK_DEBUG, "I received a packet for me with payload: %s\n", hex);

		if(mesh->receive_cb)
			mesh->receive_cb(mesh, (meshlink_node_t *)source, payload, len);
		return;
	}

	if(!owner->status.reachable) {
		//TODO: check what to do here, not just print a warning
		logger(mesh, MESHLINK_WARNING, "The owner of a packet in the route() function is unreachable. Dropping packet.\n");
		return;
	}

	via = (owner->via == mesh->self) ? owner->nexthop : owner->via;
	if(via == source) {
		logger(mesh, MESHLINK_ERROR, "Routing loop for packet from %s (%s)!", source->name, source->hostname);
		return;
	}

	send_packet(mesh, owner, packet);
	return;
}
Esempio n. 21
0
File: done.c Progetto: T-J-Teru/tdl
/*}}}*/
int process_undo(char **x)/*{{{*/
{
  struct node *n;
  int do_descendents;

  while (*x) {
    do_descendents = include_descendents(*x); /* May modify *x */
    n = lookup_node(*x, 0, NULL);
    if (!n) return -1;
    n->done = 0;
    undo_ancestors(n);
    if (do_descendents) {
      undo_descendents(n);
    }
    x++;
  }

  return 0;

}
Esempio n. 22
0
void setup_outgoing_connection(outgoing_t *outgoing) {
	connection_t *c;
	node_t *n;

	outgoing->event = NULL;

	n = lookup_node(outgoing->name);

	if(n)
		if(n->connection) {
			ifdebug(CONNECTIONS) logger(LOG_INFO, "Already connected to %s", outgoing->name);

			n->connection->outgoing = outgoing;
			return;
		}

	c = new_connection();
	c->name = xstrdup(outgoing->name);
	c->outcipher = myself->connection->outcipher;
	c->outdigest = myself->connection->outdigest;
	c->outmaclength = myself->connection->outmaclength;
	c->outcompression = myself->connection->outcompression;

	init_configuration(&c->config_tree);
	read_connection_config(c);

	outgoing->cfg = lookup_config(c->config_tree, "Address");

	if(!outgoing->cfg) {
		logger(LOG_ERR, "No address specified for %s", c->name);
		free_connection(c);
		return;
	}

	c->outgoing = outgoing;
	c->last_ping_time = now;

	connection_add(c);

	do_outgoing_connection(c);
}
Esempio n. 23
0
void bbst_delete(bbst tree, void* key, compare_func compare) {
    node child;
    node n = lookup_node(tree, key, compare);
    if (n == NULL) return;
    if (n->left != NULL && n->right != NULL) {
        /* find the biggest of the lower */
        node predecessor = maximum_node(n->left);
        n->key           = predecessor->key;
        n->value         = predecessor->value;
        n                = predecessor;
    }

    assert(n->left == NULL || n->right == NULL);
    child = n->right == NULL ? n->left : n->right;
    if (node_color(n) == BLACK) {
        n->color = node_color(child);
        delete_case1(tree, n);
    }
    replace_node(tree, n, child);
    if (n->parent == NULL && child != NULL)
        child->color = BLACK;
    free(n);
}
Esempio n. 24
0
File: done.c Progetto: T-J-Teru/tdl
/*}}}*/
static int internal_done(time_t when, char **x)/*{{{*/
{
  struct node *n;
  int do_descendents;

  clear_flags(&top);

  while (*x) {
    do_descendents = include_descendents(*x); /* May modify *x */
    n = lookup_node(*x, 0, NULL);
    if (!n) return -1;
    n->flag = 1;
    if (do_descendents) {
      mark_all_descendents(n);
    }
    n->scratch = *x; /* Safe to alias, *x has long lifetime */
    x++;
  }
   
  mark_done_from_bottom_up(&top, when);

  return 0;
}
Esempio n. 25
0
File: rbtree.c Progetto: hgn/ospfd
struct rbtree_node *rbtree_delete(struct rbtree* t, void* key)
{
    struct rbtree_node* child;
    struct rbtree_node* n = lookup_node(t, key);
    if (n == NULL) return NULL; /* Key not found, do nothing */
    if (n->left != NULL && n->right != NULL) {
        /* Copy key/data from predecessor and then delete it instead */
        struct rbtree_node* pred = maximum_node(n->left);
        n->key = pred->key;
        n->data = pred->data;
        n = pred;
    }

    assert(n->left == NULL || n->right == NULL);
    child = n->right == NULL ? n->left : n->right;
    if (node_color(n) == BLACK) {
        n->color = node_color(child);
        delete_case1(t, n);
    }
    replace_node(t, n, child);

    return n;
}
Esempio n. 26
0
/*
 *  l_rbtreeDelete()
 *
 *      Input:  t (rbtree, including root node)
 *              key (delete the node with this key)
 *      Return: void
 */
void
l_rbtreeDelete(L_RBTREE  *t,
               RB_TYPE    key)
{
node  *n, *child;

    PROCNAME("l_rbtreeDelete");

    if (!t) {
        L_ERROR("tree is null\n", procName);
        return;
    }

    n = lookup_node(t, key);
    if (n == NULL) return;  /* Key not found, do nothing */
    if (n->left != NULL && n->right != NULL) {
            /* Copy key/value from predecessor and then delete it instead */
        node *pred = maximum_node(n->left);
        n->key   = pred->key;
        n->value = pred->value;
        n = pred;
    }

        /* n->left == NULL || n->right == NULL */
    child = n->right == NULL ? n->left  : n->right;
    if (node_color(n) == L_BLACK_NODE) {
        n->color = node_color(child);
        delete_case1(t, n);
    }
    replace_node(t, n, child);
    if (n->parent == NULL && child != NULL)  /* root should be black */
        child->color = L_BLACK_NODE;
    LEPT_FREE(n);

    verify_properties(t);
}
Esempio n. 27
0
bool key_changed_h(connection_t *c) {
	char name[MAX_STRING_SIZE];
	node_t *n;

	if(sscanf(c->buffer, "%*d %*x " MAX_STRING, name) != 1) {
		logger(LOG_ERR, "Got bad %s from %s (%s)", "KEY_CHANGED",
			   c->name, c->hostname);
		return false;
	}

	if(!check_id(name)) {
		logger(LOG_ERR, "Got bad %s from %s (%s): %s", "KEY_CHANGED", c->name, c->hostname, "invalid name");
		return false;
	}

	if(seen_request(c->buffer))
		return true;

	n = lookup_node(name);

	if(!n) {
		logger(LOG_ERR, "Got %s from %s (%s) origin %s which does not exist",
			   "KEY_CHANGED", c->name, c->hostname, name);
		return true;
	}

	n->status.validkey = false;
	n->last_req_key = 0;

	/* Tell the others */

	if(!tunnelserver)
		forward_request(c);

	return true;
}
Esempio n. 28
0
bool add_edge_h(connection_t *c) {
	edge_t *e;
	node_t *from, *to;
	char from_name[MAX_STRING_SIZE];
	char to_name[MAX_STRING_SIZE];
	char to_address[MAX_STRING_SIZE];
	char to_port[MAX_STRING_SIZE];
	sockaddr_t address;
	uint32_t options;
	int weight;

	if(sscanf(c->buffer, "%*d %*x "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" %x %d",
			  from_name, to_name, to_address, to_port, &options, &weight) != 6) {
		logger(LOG_ERR, "Got bad %s from %s (%s)", "ADD_EDGE", c->name,
			   c->hostname);
		return false;
	}

	/* Check if names are valid */

	if(!check_id(from_name) || !check_id(to_name)) {
		logger(LOG_ERR, "Got bad %s from %s (%s): %s", "ADD_EDGE", c->name,
			   c->hostname, "invalid name");
		return false;
	}

	if(seen_request(c->buffer))
		return true;

	/* Lookup nodes */

	from = lookup_node(from_name);
	to = lookup_node(to_name);

	if(tunnelserver &&
	   from != myself && from != c->node &&
	   to != myself && to != c->node) {
		/* ignore indirect edge registrations for tunnelserver */
		ifdebug(PROTOCOL) logger(LOG_WARNING,
		   "Ignoring indirect %s from %s (%s)",
		   "ADD_EDGE", c->name, c->hostname);
		return true;
	}

	if(!from) {
		from = new_node();
		from->name = xstrdup(from_name);
		node_add(from);
	}

	if(!to) {
		to = new_node();
		to->name = xstrdup(to_name);
		node_add(to);
	}


	/* Convert addresses */

	address = str2sockaddr(to_address, to_port);

	/* Check if edge already exists */

	e = lookup_edge(from, to);

	if(e) {
		if(e->weight != weight || e->options != options || sockaddrcmp(&e->address, &address)) {
			if(from == myself) {
				ifdebug(PROTOCOL) logger(LOG_WARNING, "Got %s from %s (%s) for ourself which does not match existing entry",
						   "ADD_EDGE", c->name, c->hostname);
				send_add_edge(c, e);
				return true;
			} else {
				ifdebug(PROTOCOL) logger(LOG_WARNING, "Got %s from %s (%s) which does not match existing entry",
						   "ADD_EDGE", c->name, c->hostname);
				edge_del(e);
				graph();
			}
		} else
			return true;
	} else if(from == myself) {
		ifdebug(PROTOCOL) logger(LOG_WARNING, "Got %s from %s (%s) for ourself which does not exist",
				   "ADD_EDGE", c->name, c->hostname);
		contradicting_add_edge++;
		e = new_edge();
		e->from = from;
		e->to = to;
		send_del_edge(c, e);
		free_edge(e);
		return true;
	}

	e = new_edge();
	e->from = from;
	e->to = to;
	e->address = address;
	e->options = options;
	e->weight = weight;
	edge_add(e);

	/* Tell the rest about the new edge */

	if(!tunnelserver)
		forward_request(c);

	/* Run MST before or after we tell the rest? */

	graph();

	return true;
}
Esempio n. 29
0
bool del_edge_h(connection_t *c) {
	edge_t *e;
	char from_name[MAX_STRING_SIZE];
	char to_name[MAX_STRING_SIZE];
	node_t *from, *to;

	if(sscanf(c->buffer, "%*d %*x "MAX_STRING" "MAX_STRING, from_name, to_name) != 2) {
		logger(LOG_ERR, "Got bad %s from %s (%s)", "DEL_EDGE", c->name,
			   c->hostname);
		return false;
	}

	/* Check if names are valid */

	if(!check_id(from_name) || !check_id(to_name)) {
		logger(LOG_ERR, "Got bad %s from %s (%s): %s", "DEL_EDGE", c->name,
			   c->hostname, "invalid name");
		return false;
	}

	if(seen_request(c->buffer))
		return true;

	/* Lookup nodes */

	from = lookup_node(from_name);
	to = lookup_node(to_name);

	if(tunnelserver &&
	   from != myself && from != c->node &&
	   to != myself && to != c->node) {
		/* ignore indirect edge registrations for tunnelserver */
		ifdebug(PROTOCOL) logger(LOG_WARNING,
		   "Ignoring indirect %s from %s (%s)",
		   "DEL_EDGE", c->name, c->hostname);
		return true;
	}

	if(!from) {
		ifdebug(PROTOCOL) logger(LOG_ERR, "Got %s from %s (%s) which does not appear in the edge tree",
				   "DEL_EDGE", c->name, c->hostname);
		return true;
	}

	if(!to) {
		ifdebug(PROTOCOL) logger(LOG_ERR, "Got %s from %s (%s) which does not appear in the edge tree",
				   "DEL_EDGE", c->name, c->hostname);
		return true;
	}

	/* Check if edge exists */

	e = lookup_edge(from, to);

	if(!e) {
		ifdebug(PROTOCOL) logger(LOG_WARNING, "Got %s from %s (%s) which does not appear in the edge tree",
				   "DEL_EDGE", c->name, c->hostname);
		return true;
	}

	if(e->from == myself) {
		ifdebug(PROTOCOL) logger(LOG_WARNING, "Got %s from %s (%s) for ourself",
				   "DEL_EDGE", c->name, c->hostname);
		contradicting_del_edge++;
		send_add_edge(c, e);	/* Send back a correction */
		return true;
	}

	/* Tell the rest about the deleted edge */

	if(!tunnelserver)
		forward_request(c);

	/* Delete the edge */

	edge_del(e);

	/* Run MST before or after we tell the rest? */

	graph();

	/* If the node is not reachable anymore but we remember it had an edge to us, clean it up */

	if(!to->status.reachable) {
		e = lookup_edge(to, myself);
		if(e) {
			if(!tunnelserver)
				send_del_edge(broadcast, e);
			edge_del(e);
		}
	}

	return true;
}
Esempio n. 30
0
static PRESULT win_search_update_progress(UINT8 progress_prec)
{	
	UINT8 result = PROC_LOOP;
	win_popup_choice_t popup_result=WIN_POP_CHOICE_NULL;
	UINT8 back_save;
	PROGRESS_BAR* bar;
	TEXT_FIELD* txt;
	P_NODE node;
	UINT8 str[32];

	DBG_PRINTF("Enter %s....\n",__FUNCTION__);

	BOOL is_flash_full = FALSE;
	bar = &srch_progress_bar;
	txt = &srch_progress_txt;
	if(progress_prec == 150)
	{
		progress_prec = 100;
		is_flash_full = TRUE;
	}

	OSD_SetProgressBarPos(bar, progress_prec);
	if(progress_prec< 3)
		bar->wTickFg = WSTL_NOSHOW_IDX;
	else
		bar->wTickFg = PROGRESSBAR_PROGRESS_SH_IDX;
	OSD_SetTextFieldContent(txt, STRING_NUM_PERCENT,progress_prec);
	if(win_search_param.as_method != AS_METHOD_NIT_TP &&
		win_search_param.as_method != AS_METHOD_NIT&&
		win_search_param.as_method != AS_METHOD_MULTI_NIT)
	{
		OSD_DrawObject( (POBJECT_HEAD)bar, C_UPDATE_ALL);
		OSD_DrawObject( (POBJECT_HEAD)txt, C_UPDATE_ALL);
	}/*If search mode is AS_METHOD_NIT_TP/AS_METHOD_NIT/AS_METHOD_MULTI_NIT, do not show progress bar*/	

	
	if(progress_prec == 100) // is completed ?
	{
		// stop drawave timer, at first
		//osal_timer_activate(win_search_tmr_id, FALSE);
				
		if((srch_ch_cnt[0] != 0x0)  // radio
		|| (srch_ch_cnt[1] != 0x0))// tv
		{
			//win_search_save_data(TRUE);
		}
		else // not find
		{
			if(!is_flash_full)
			{
				INT32 ret = 0;

				if(pid_search_flg)		
				{
#ifdef NEW_DEMO_FRAME
					struct dmx_device *dmx = (struct dmx_device *)dev_get_by_id(HLD_DEV_TYPE_DMX, 0);
					ret = as_prog_pid_search(dmx, 1, pid_search_VPid,pid_search_APid, pid_search_PPid);
#else
					ret = as_prog_pid_search(1,pid_search_VPid,pid_search_APid,pid_search_PPid);
#endif
					if(ret)
					{//add node
						MEMSET(&node,0,sizeof(node));
						node.sat_id = pid_search_tp>>NODE_ID_TP_BIT;
						node.tp_id = pid_search_tp;
						node.video_pid = pid_search_VPid;
						node.audio_count = 1;
						node.audio_pid[0] = pid_search_APid;
						node.pcr_pid = pid_search_PPid;
						node.av_flag =1;
						sprintf(str,"tp%d_%d",node.tp_id,node.video_pid);
						ComAscStr2Uni(str, (UINT16*)node.service_name);
						if(SUCCESS!= lookup_node(TYPE_PROG_NODE, &node, node.tp_id))
						{
							add_node(TYPE_PROG_NODE, node.tp_id, &node);
							update_data();
						}
					}
				}
				if(!ret)
				{
                    win_search_last_tp_ok_failed(srch_tp_cnt);

					win_compopup_init(WIN_POPUP_TYPE_OK);
					win_compopup_set_msg(NULL,NULL,RS_MSG_NO_PROGRAM_FOUND);
					win_compopup_open_ext(&back_save);
				}
			}			
		}
		
		if(is_flash_full==TRUE)
		{
            win_search_last_tp_ok_failed(srch_tp_cnt);

			win_compopup_init(WIN_POPUP_TYPE_OK);
			win_compopup_set_msg(NULL,NULL,RS_MSG_SPACE_FULL);
			win_compopup_open_ext(&back_save);
		}
		
		result = PROC_LEAVE;
	}