/* * Basic broadcast. The broadcast takes N turns, all sends are done by the * same node (one at each turn). * Note that like every functions defined here, they have the type NodesFct. */ void BasicBroadcast(int id, Message m){ char* event; Message msgOut; int i; //Events Rules while((event = getNextExternalEvent(id)) != NULL){ printf("event received %d %s\n", id, event); //Read the first event if(!strcmp(event, "broadcast")){ //start a basic broadcast: //send hello to every nodes for(i = 0; i < getNbNodes(); i++){ msgOut = initMessage("Hello\0", id, id, i); if(i != id){ Send(msgOut); } else { deliver(msgOut,id); deleteMessage(msgOut); } } } free(event); } //Message Rules if(NULL != m){ deliver(m,id); deleteMessage(m); } }
/* * Pipeline broadcast. This protocol takes 1 turn to broadcast, the node * performing the broadcast sends the message to the next note, which in turn * transmits the message to its neighbour and so on. * Note that like every functions defined here, they have the type NodesFct. */ void PipelineBroadcast(int id, Message m){ char* event; Message msg, fwd; int neighbor; // Event Rules while((event = getNextExternalEvent(id)) != NULL){ printf("event received %i %s\n",id, event); // Read the first event if(0 == strcmp(event, "broadcast")){ neighbor = (id + 1) % getNbNodes(); msg = initMessage("Hello\0", id, id, neighbor); Send(msg); deliver(msg,id); } free(event); } // Message Rules if(NULL != m){ deliver(m, id); // Forward the message if need be neighbor = (id + 1) % getNbNodes(); if(neighbor != m->origin){ fwd = initMessage(m->msg, m->origin, id, neighbor); Send(fwd); } // Free the local message deleteMessage(m); } }
mreturn mod_log_archiver(mapi m, void *arg) { jid svcs = (jid) arg; xmlnode x; char ts[101]; struct tm now; unsigned long ltime; if (m->packet->type != JPACKET_MESSAGE) return M_IGNORE; log_debug("archiving message"); /* get a copy wrapped w/ a route and stamp it w/ a type='archive' (why not?) */ x = xmlnode_wrap(xmlnode_dup(m->packet->x), "route"); xmlnode_put_attrib(x, "type", "archive"); /* Mark the route with an direction attribute */ switch (m->e) { case es_IN: xmlnode_put_attrib(x, "direction", "in"); break; case es_OUT: xmlnode_put_attrib(x, "direction", "out"); break; } /* Mark the route with a timeStamp attribute */ time(<ime); #ifdef WIN32 now = *localtime(<ime); #else localtime_r(<ime, &now); #endif strftime((char *) ts, 100, "%m/%d/%Y %H:%M:%S", &now); xmlnode_put_attrib(x, "stamp", ts); /* if there's more than one service, copy to the others */ for (; svcs->next != NULL; svcs = svcs->next) { xmlnode_put_attrib(x, "to", jid_full(svcs)); deliver(dpacket_new(xmlnode_dup(x)), NULL); } /* send off to the last (or only) one */ xmlnode_put_attrib(x, "to", jid_full(svcs)); deliver(dpacket_new(x), NULL); return M_PASS; }
void con_room_forward_decline(cnr room, jpacket jp, xmlnode decline) { cnu user; jid user_jid; if (room == NULL || decline == NULL || jp == NULL) { log_warn(NAME, "[%s] Aborting - NULL attribute found", FZONE); xmlnode_free(jp->x); return; } user_jid=jid_new(decline->p,xmlnode_get_attrib(decline,"to")); if ((room->invitation == 1 && !is_member(room, jp->from) && !is_owner(room, jp->from)) || user_jid == NULL) { log_warn(NAME, "[%s] Aborting - User is not allowed to send a decline", FZONE); jutil_error(jp->x, TERROR_MUC_OUTSIDE); deliver(dpacket_new(jp->x), NULL); return; } if (user_jid->resource == NULL) { log_warn(NAME, "[%s] Aborting - cannot send back decline, bare jid found", FZONE); return; } if (room->visible == 1) { user = g_hash_table_lookup(room->remote, jid_full(jid_fix(user_jid))); } else { user = g_hash_table_lookup(room->local, user_jid->resource); } if (user == NULL){ log_warn(NAME, "[%s] Aborting - Decline recipient is not in the room", FZONE); jutil_error(jp->x, TERROR_MUC_OUTSIDE); deliver(dpacket_new(jp->x), NULL); return; } log_debug(NAME, "[%s] Sending invitation decline", FZONE); xmlnode_put_attrib(decline, "from", jid_full(jp->from)); xmlnode_hide_attrib(decline, "to"); xmlnode_put_attrib(jp->x, "to", jid_full(user->realid)); xmlnode_put_attrib(jp->x, "from", jid_full(room->id)); log_debug(NAME, "[%s] >>>%s<<<", FZONE, xmlnode2str(jp->x)); deliver(dpacket_new(jp->x), NULL); return; }
result base_to_deliver(instance id, dpacket p, void *arg) { char *log_data = xmlnode_get_data(p->x); char *subject; xmlnode message; if (log_data == NULL) return r_ERR; message = xmlnode_new_tag("message"); xmlnode_insert_cdata(xmlnode_insert_tag(message, "body"), log_data, -1); subject = spools(xmlnode_pool(message), "Log Packet from ", xmlnode_get_attrib(p->x, "from"), xmlnode_pool(message)); xmlnode_insert_cdata(xmlnode_insert_tag(message, "thread"), shahash(subject), -1); xmlnode_insert_cdata(xmlnode_insert_tag(message, "subject"), subject, -1); xmlnode_put_attrib(message, "from", xmlnode_get_attrib(p->x, "from")); xmlnode_put_attrib(message, "to", (char *) arg); deliver(dpacket_new(message), id); pool_free(p->p); return r_DONE; }
int messages::system(const char *to, const char *text) { char from[MAX_URI_SIZE]; const char *scheme; const char *sysid = stack::sip.system; const char *host = stack::sip.published; unsigned short port = sip_port; if(stack::sip_tlsmode) scheme = "sips"; else scheme = "sip"; if(!host) { host = "127.0.0.1"; #ifdef AF_INET6 if(!host && stack::sip_family == AF_INET6) host = "::1"; #endif } if(strchr(host, ':')) snprintf(from, sizeof(from), "<%s:%s@[%s]:%u>", scheme, sysid, host, port); else snprintf(from, sizeof(from), "<%s:%s@%s:%u>", scheme, sysid, host, port); return deliver(to, sysid, from, (caddr_t)text, strlen(text), "text/plain"); }
int messages::deliver(const char *to, const char *reply, const char *from, caddr_t text, size_t len, const char *msgtype, const char *digest) { message *msg; if(!msgtype) msgtype = "text/plain"; if(len > sizeof(msg->body)) return SIP_MESSAGE_TOO_LARGE; msglock.lock(); msg = static_cast<message *>(freelist); if(msg) freelist = msg->getNext(); msglock.unlock(); if(!msg) { ++allocated; msg = new message(); } msg->create(); String::set(msg->reply, sizeof(msg->reply), reply); String::set(msg->from, sizeof(msg->from), from); String::set(msg->type, sizeof(msg->type), msgtype); memset(msg->body, 0, sizeof(msg->body)); if(len) memcpy(msg->body, text, len); msg->msglen = len; if(!strchr(to, '@')) { String::set(msg->user, sizeof(msg->user), to); return deliver(msg); } return remote(to, msg, digest); }
void ConfigEndpoint::load(std::string configname){ this->configname = configname; std::ifstream file_stream; file_stream.open(configname.c_str()); //TODO: parsen und einfügen std::string line; while(std::getline(file_stream,line)){ if(line.find('#')!=std::string::npos){ try { Command_ptr command(new Command(line, this->shared_from_this())); { boost::mutex::scoped_lock lock(commandsMutex); commands.push_back(command); } } catch (const std::invalid_argument& ia) { std::ostringstream oss; oss << "Found a command that might not be conform with command format: " << line; log(oss.str()); } } } file_stream.close(); registerEndpoint(); { boost::mutex::scoped_lock lock(commandsMutex); for (std::list<Command_ptr>::const_iterator command = commands.begin(), end = commands.end(); command != end; ++command) { deliver(*command); } } }
/* NOTE: any jpacket sent to deliver *MUST* match jpacket_new(p->x), * jpacket is simply a convenience wrapper */ void js_deliver(jsmi si, jpacket p) { if (p->to == NULL) { log_warn(NULL, "jsm: Invalid Recipient, returning data %s", xmlnode2str(p->x)); js_bounce(si, p->x, TERROR_BAD); return; } if (p->from == NULL) { log_warn(NULL, "jsm: Invalid Sender, discarding data %s", xmlnode2str(p->x)); xmlnode_free(p->x); return; } log_debug("deliver(to[%s],from[%s],type[%d],packet[%s])", jid_full(p->to), jid_full(p->from), p->type, xmlnode2str(p->x)); /* is it our */ if (j_strcmp(si->host, p->to->server) == 0) { js_deliver_local(si, p); return; } deliver(dpacket_new(p->x), si->i); }
int submit_mail(const char * to, const char * subject, const char * body) { char ** addrs; char ** ad; char * msg; int status; /* Parse the address list so we can form a reasonable one for the user to see in the message. */ addrs = arpaPhrase(to); msg = formatMessage(addrs, subject, body); status = deliver(addrs, msg); for (ad = addrs; *ad; ad++) { free(*ad); } free(addrs); free(msg); return(status); }
/* actually deliver the xdb request */ void xdb_deliver(instance i, xdbcache xc, int another_thread) { xmlnode x; char ids[15]; x = xmlnode_new_tag("xdb"); if(xc->set) { xmlnode_put_attrib(x,"type","set"); xmlnode_insert_tag_node(x,xc->data); /* copy in the data */ if(xc->act != NULL) xmlnode_put_attrib(x,"action",xc->act); if(xc->match != NULL) xmlnode_put_attrib(x,"match",xc->match); } else { xmlnode_put_attrib(x,"type","get"); } xmlnode_put_attrib(x,"to",jid_full(xc->owner)); xmlnode_put_attrib(x,"from",i->id); xmlnode_put_attrib(x,"ns",xc->ns); sprintf(ids,"%d",xc->id); xmlnode_put_attrib(x,"id",ids); /* to track response */ if (another_thread) { xdb_resend cur = pmalloco(xmlnode_pool(x),sizeof(_xdb_resend)); cur->x = x; cur->i = i; mtq_send(NULL,NULL,resend_xdb,(void *)cur); } else { deliver(dpacket_new(x), i); } }
void * sender(void *msg_queue) { send_queue = (struct msg_queue *)msg_queue; printf("Initializing sender thread...\n"); sleep(2); struct msg_queue *queue = (struct msg_queue *)msg_queue; struct msg_container *next; pthread_t interactive_thread; int x = pthread_create(&interactive_thread,NULL,(void *)interactive,NULL); for(;;) { /* If there are messages to be processed, deliver them */ if(queue->length!=0) { next = dequeue(queue); char src[100], dst[100]; inet_ntop(AF_INET,&(next->msg_src),src,INET_ADDRSTRLEN); inet_ntop(AF_INET,&(next->msg_dest),dst,INET_ADDRSTRLEN); deliver(next); } sleep(1); } return((void *)0); }
void EnableIndicationsResponseHandler::deliver( const Array<CIMIndication>& cimIndications) { OperationContext context; deliver(context, cimIndications); }
void EnableIndicationsResponseHandler::deliver(const OperationContext & context, const Array<CIMIndication> & cimIndications) { for(Uint32 i = 0, n = cimIndications.size(); i < n; i++) { deliver(context, cimIndications[i]); } }
/* * Total Order Broadcast with good throughput. * Note that like every functions defined here, they have the type NodesFct. */ void TOBThroughputRodBroadcast(int id, Message m){ char* event; Message msgOut; //Events Rules while((event = getNextExternalEvent(id)) != NULL){ printf("Event received %d %s\n", id, event); //Read the first event if(!strcmp(event, "broadcast")){ if(0 == id){ // The broadcast is your own, deliver msgOut = initMessage("Hello\0", id, id, id); deliver(msgOut, id); deleteMessage(msgOut); // Pass the message to your successor if(1 != getNbNodes()){ msgOut = initMessage("Hello\0", 0, 0, 1); Send(msgOut); } } else { // Send the message to process 0 msgOut = initMessage("Hello\0", id, id, 0); Send(msgOut); } } free(event); } // Message Rules if(NULL != m){ if(0 == id) printf("0 receives a message to relay from %i\n", m->sender); deliver(m, id); // If not the last of the pipeline... if(id != getNbNodes() - 1){ // Transfer the message to you successor msgOut = initMessage(m->msg, m->origin, id, id + 1 % getNbNodes()); Send(msgOut); } deleteMessage(m); } }
void delegate(T& x) { auto rp = self_->make_response_promise(); if (! rp.pending()) { CAF_LOG_DEBUG("suppress response message: invalid response promise"); return; } deliver(rp, x); }
/* * Tree broadcast. This protocol needs log(NbNodes) turn to broadcast. * Every node sends to its succesors. * Note that like every functions defined here, they have the type NodesFct. */ void TreeBroadcast(int id, Message m){ char* event; Message msgOut; int nTurn; //Events Rules while((event = getNextExternalEvent(id)) != NULL){ printf("Event received %d %s\n", id, event); //Read the first event if(!strcmp(event, "broadcast")){ //start a tree broadcast: //Iniatialize the message for(nTurn = 0; nTurn < log2(getNbNodes()); nTurn++){ //at the first step of the tree broadcast, we send a message //to our successor msgOut = initMessage("Hello\0", id, id, (int)(pow(2,nTurn)+id)%getNbNodes()); Send(msgOut); } // Deliver the message localy msgOut = initMessage("Hello\0", id, id, id); deliver(msgOut,id); deleteMessage(msgOut); } free(event); } //Message Rules if(NULL != m){ deliver(m,id); //at a step n, a message is sent at a distance 2^n //the distance is not exactly the difference between the sender and the //receiver id because of the mod N if(m->sender < m->receiv) nTurn=log2(m->receiv-m->sender); else nTurn=log2(getNbNodes()-m->sender+m->receiv); //this turn is done, let's do the others //now we can send all the others messages for(nTurn++; nTurn<log2(getNbNodes()); nTurn++){ msgOut = initMessage(m->msg, m->origin, id, ((int)(pow(2,nTurn)+id))%getNbNodes()); Send(msgOut); } deleteMessage(m); } }
void basp_broker_state::deliver(const node_id& src_nid, actor_id src_aid, atom_value dest_name, message_id mid, std::vector<strong_actor_ptr>& stages, message& msg) { CAF_LOG_TRACE(CAF_ARG(src_nid) << CAF_ARG(src_aid) << CAF_ARG(dest_name) << CAF_ARG(msg) << CAF_ARG(mid)); deliver(src_nid, src_aid, system().registry().get(dest_name), mid, stages, msg); }
/* * Total Order Broadcast with good latency. * Note that like every functions defined here, they have the type NodesFct. */ void TOBLatencyBroadcast(int id, Message m){ char* event; Message msgOut; int i; //Events Rules while((event = getNextExternalEvent(id)) != NULL){ printf("Event received %d %s\n", id, event); //Read the first event if(!strcmp(event, "broadcast")){ if(0 == id){ // The broadcast is your own, deliver msgOut = initMessage("Hello\0", id, id, id); deliver(msgOut, id); deleteMessage(msgOut); // Pass the message to your childs for(i = 1; i < getNbNodes(); i *= 2){ msgOut = initMessage("Hello\0", id, id, i); Send(msgOut); } } else { // Send the message to process 0 msgOut = initMessage("Hello\0", id, id, 0); Send(msgOut); } } free(event); } // Message Rules if(NULL != m){ if(0 == id) printf("0 receives a message to relay from %i\n", m->sender); deliver(m, id); for(i = 2 * id + 1; i < getNbNodes(); i *= 2){ msgOut = initMessage(m->msg, m->origin, id, i); Send(msgOut); } deleteMessage(m); } }
void mine(){ while(1){ pthread_mutex_lock(&m_gold_a); if(gold_available < 1) break; printf("gold at map: %d\n", gold_available); gold_available -= 10; pthread_mutex_unlock(&m_gold_a); deliver(); } }
void Room::leave(Session::chat_session_ptr participant) { // On informe les sessions de la room // (2) DownMessage e; e.m_type = DownMessage::PLAYER_LEFT; e.m_info = "A player left"; deliver(e); m_participants.erase(participant);// puis on le détruit }
void EnableIndicationsResponseHandler::deliver(const CIMIndication & cimIndication) { OperationContext context; Array<CIMObjectPath> subscriptionInstanceNames; context.insert(SubscriptionInstanceNamesContainer(subscriptionInstanceNames)); deliver(context, cimIndication); }
void Room::broadcast() { DownMessage msg; msg.m_type = DownMessage::WORLD_STATE; for (std::set<chat_session_ptr>::iterator it = m_participants.begin(); m_participants.end() != it; it++) { msg.m_players.push_back((**it).getPlayer()); } deliver(msg); }
int main() { init("COM3"); int i=0; int flag=0; while(1) { flag=0; if(no_of_objects==0) { flag=1; printf("\nAll objects sorted by Gripper\n\n"); } if(flag==1 && allfree()) { printf("\n\nDelivered all objects\n"); printf("Project successfully done :) \n"); while(1) {} break; } if(gripper[0].is_free && flag==0) { collect_obj(0); gripper[0].is_free = false; } data=new char[20]; getString(); printf("I read %s \n",data); if(data[0] == 'd') // for delivery bot { deliver(data); } else if(data[0] == 'g') { if(data[3] == '\0') collect_obj(0); else if(data[3] == '*') //object dropped successfully by gripper { updateafterdrop(0); } else { char* temp = new char; temp = data+3; printf("Received rfid: %s\n",temp); int i = getdestn_rfid(temp); gripper[0].dest_bot = i; gripper[0].destn = delivery[i].p; collect_obj(0); } } else printf("Error signal\n"); } }
void send_receive(uint16_t to, uint16_t from) { Thread *sender, *receiver, *current = scheduler_current(); if (to) { receiver = thread_get(to); if (receiver->state != WAIT_RECEIVING || !(receiver->waitingFor == (uint16_t)-1 || receiver->waitingFor == current->tid)) { if (from) return scheduler_wait(to, WAIT_SEND_RECV); else return scheduler_wait(to, WAIT_SENDING); } deliver(current, receiver); scheduler_unblock(receiver); } if (from) { if (!list_empty(¤t->waitingList)) { sender = list_item(list_pop(¤t->waitingList), Thread, queueLink); deliver(sender, current); if (sender->state == WAIT_SENDING) scheduler_unblock(sender); else sender->state = WAIT_RECEIVING; } else scheduler_wait(from, WAIT_RECEIVING); } return; }
static int deliverSWP(SwpState state, Msg *frame) { SwpHdr hdr; char *hbuf; hbuf = msgStripHdr(frame, HLEN); load_swp_hdr(&hdr, hbuf); if (hdr->Flags & FLAG_ACK_VALID) { if (swpInWindow(hdr.AckNum, state->LAR + 1, state->LFS)) { do { struct sendQ_slot *slot; slot = &state->sendQ[++state->LAR % SWS]; evCancel(slot->timeout); msgDestroy(&slot->msg); semSignal(&state->sendWindowNotFull); } while (state->LAR != hdr.Acknum); } } if (hdr.Flags & FLAG_HAS_DATA) { struct recvQ_slot, *slot; //received data packet---do RECEIVER side slot = &state->recvQ[hdr.SeqNum % RWS]; if (!swpInWindow(hdr.SeqNum, state->NFE, state->NFE + RWS - 1)) { //drop the message return SUCCESS; } msgSaveCopy(&slot->msg, frame); slot->received = TRUE; if (hdr.SeqNum == state->NFE) { Msg m; while (slot->received) { deliver(HLP, &slot->msg); msgDestroy(&slot->msg); slot->received = FALSE; slot = &state->recvQ[++state->NFE % RWS]; } //send ACK prepare_ack(&m, state->NFE - 1); send(LINK, &m); msgDestroy(&m); } } return SUCCESS; }
void dnsrv_resend(xmlnode pkt, char *ip, char *to) { if(ip != NULL) { pkt = xmlnode_wrap(pkt,"route"); xmlnode_put_attrib(pkt, "to", to); xmlnode_put_attrib(pkt, "ip", ip); }else{ jutil_error(pkt, (terror){502, "Unable to resolve hostname."}); xmlnode_put_attrib(pkt, "iperror", ""); } deliver(dpacket_new(pkt),NULL); }
TEST_F(PerformanceObserverTest, Deliver) { V8TestingScope scope; initialize(scope.getScriptState()); Persistent<PerformanceEntry> entry = PerformanceMark::create("m", 1234); EXPECT_EQ(0, numPerformanceEntries()); m_observer->enqueuePerformanceEntry(*entry); EXPECT_EQ(1, numPerformanceEntries()); deliver(); EXPECT_EQ(0, numPerformanceEntries()); }
/* delivers a route packet to all listeners for this session */ static void js_session_route(session s, xmlnode in) { /* NULL means this is an error from the session ending */ if (in == NULL) { in = xmlnode_new_tag("route"); xmlnode_put_attrib(in, "type", "error"); xmlnode_put_attrib(in, "error", "Disconnected"); } else { in = xmlnode_wrap(in, "route"); } xmlnode_put_attrib(in, "from", jid_full(s->route)); xmlnode_put_attrib(in, "to", jid_full(s->sid)); deliver(dpacket_new(in), s->si->i); }
void QQFakeServer::sendMessage( const QString &contactId, const QString &message ) { // see what contact the message is for // if it's for Echo, respond immediately kDebug( 14210 ) << "Message for: " << contactId << ", is: " << message; kDebug( 14210 ) << "recipient is echo, coming back at you."; // put the message in a map and start a timer to tell it to deliver itself. //emit messageReceived( QString::fromLatin1( "echo: " ) + message ); QString messageId = contactId + QString::fromLatin1(": "); QQIncomingMessage* msg = new QQIncomingMessage( this, messageId + message ); m_incomingMessages.append( msg ); QTimer::singleShot( 1000, msg, SLOT(deliver()) ); // This removes any delivered messages purgeMessages(); }