/** The JOIN message is answered by a JOINACK or a JOINNACK message. * If the transmit time is too long, a JOINNACK is returned. * If not, an JOINACK is answered, with all the peer's addresses * that are in the leafset. */ void Handle (Chimera& chimera, const Host&, const Packet& pckt) { pf_addr addr = pckt.GetArg<pf_addr>(CHIMERA_JOIN_ADDRESS); Host host = hosts_list.GetHost(addr); double elapsed_time = time::dtime() - host.GetFailureTime(); if(elapsed_time < Chimera::GRACEPERIOD) { Packet join_nack(ChimeraJoinNAckType, chimera.GetMe().GetKey(), host.GetKey()); join_nack.SetArg(CHIMERA_JOIN_NACK_ADDRESS, addr); chimera.Send(host, join_nack); pf_log[W_ROUTING] << "JOIN request from node " << host << " rejected, " << "elapsed time since failure = " << elapsed_time << " sec"; return; } std::vector<Host> leafset = chimera.GetRouting()->getLeafset(); addr_list addresses; for(std::vector<Host>::iterator it = leafset.begin(); it != leafset.end(); ++it) addresses.push_back(it->GetAddr()); addresses.push_back(chimera.GetMe().GetAddr()); Packet join_ack(ChimeraJoinAckType, chimera.GetMe().GetKey(), host.GetKey()); join_ack.SetArg(CHIMERA_JOIN_ACK_ADDRESSES, addresses); if(!chimera.Send(host, join_ack)) pf_log[W_ROUTING] << "Send join ACK message failed!"; }
/** We update the routing infrastructure with the given addresses */ void Handle (Chimera& chimera, const Host&, const Packet& pckt) { addr_list address = pckt.GetArg<addr_list>(CHIMERA_PIGGY_ADDRESSES); for(addr_list::iterator it = address.begin(); it != address.end(); ++it) { Host host = hosts_list.GetHost(*it); /* After a peer failed, we wait some time before adding it back. */ if(time::dtime() - host.GetFailureTime() > Chimera::GRACEPERIOD) chimera.GetRouting()->add(host); else pf_log[W_ROUTING] << "Refused to add " << host << " to routing table"; } }