Exemplo n.º 1
0
  int open (void * )
  {
    if (super::open (0) == -1)
      return -1;

    InetAddr peerAddr;
    if (this->getStream ().getRemoteAddr (peerAddr) == 0) {
      std::string strPeer = peerAddr.toString ();
      cout << "connection from " << strPeer << endl;
    }

    return 0;
  }
Exemplo n.º 2
0
int PublisherHandler::open(void *) {
  if (super::open(0) == -1)
    return -1;

  InetAddr peerAddr;
  if (this->getStream().getRemoteAddr(peerAddr) == 0) {
    std::string strPeer = peerAddr.toString();
    ICC_DEBUG("connection from %s", strPeer.c_str());
  }

  msg = 0;
  return 0;
}
Exemplo n.º 3
0
int MsgServerHandler::open(void *) {
    if (super::open(0) == -1)
        return -1;

    InetAddr peerAddr;
    if (this->getStream().getRemoteAddr(peerAddr) == 0) {
        std::string strPeer = peerAddr.toString();
        LogDebug << "MsgServerHandler::open remote connection from " << strPeer << endl;
    }

    //Block mode to avoid EWOULDBLOCK
    getStream().disable(ACE_NONBLOCK);

    msg = 0;
    return 0;
}
Exemplo n.º 4
0
void OSConfigurator_linux24::addVirtualAddressForNAT(const Network *nw)
{
    FWOptions* options=fw->getOptionsObject();
    if (options->getBool("manage_virtual_addr"))
    {
        if (virtual_addresses.empty() || 
            find(virtual_addresses.begin(),virtual_addresses.end(),
                 *(nw->getAddressPtr())) == virtual_addresses.end())
        {
            Interface *iface = findInterfaceFor( nw, fw );
            if (iface!=nullptr)
            {
                const InetAddr *addr = nw->getAddressPtr();
                InetAddr first, last;
                InetAddr a;

                first = *addr;
                last = *(nw->getBroadcastAddressPtr());

                QStringList addresses;
                for (a=first; a<last; a=a+1)
                {
                    addresses.push_back(QString("%1/32").arg(a.toString().c_str()));
                }

                if (virtual_addresses_for_nat.count(iface->getName()) > 0)
                    addresses.push_front(virtual_addresses_for_nat[iface->getName()].c_str());

                virtual_addresses_for_nat[iface->getName()] =
                    addresses.join(" ").toStdString();

                virtual_addresses.push_back( *(nw->getAddressPtr()) );
                registerVirtualAddressForNat();
            } else
                warning("Can not add virtual address " +
                        nw->getAddressPtr()->toString() +
                        " (object " + nw->getName() + ")" );
        }
    }
}
Exemplo n.º 5
0
int PublisherHandler::handleInput(ACE_HANDLE fd) {
  if (msg == 0) {
    msg = new Msg;
  }

  int result = MsgProtocol::parse(&stream, msg);
  if (result == -1) {
    ICC_ERROR("PublisherHandler::handleInput error: %s", OS::strerror(OS::map_errno(OS::last_error())));
    delete msg;
    msg = 0;
    return -1;
  } else if (result == 1) {
    return 0;
  }

  assert(result == 0);

  if (msg->messageType == Msg_KeepAlive_Probe) {
    OutputStream os;
    MsgProtocol::start(Msg_KeepAlive_ACK, &os);
    std::string t("keepAlive");
    os.write_string(t);

    InetAddr peerAddr;
    this->getStream().getRemoteAddr(peerAddr);

//    ICC_DEBUG("recved publisher keep alive probe, sending ack, peer: %s", peerAddr.toString().c_str());
    int result = MsgProtocol::send(&this->getStream(), &os);
    if (result == 0) {
//      ICC_DEBUG("send keep alive probe ack succeeded, peer: %s", peerAddr.toString().c_str());
    }

    delete msg;
    msg = 0;
    return result;
  } else if(msg->messageType == Msg_Publish) {
    OutputStream os;
    MsgProtocol::start(Msg_Publish_OK, &os);
    os.write_string("publishOK");
    os.write_int(SubscriberHandler::keepAliveTryTimes);
    os.write_int(SubscriberHandler::keepAliveTimeSpan);
    os.write_boolean(SubscriberHandler::enableBuffering);

    InetAddr peerAddr;
    this->getStream().getRemoteAddr(peerAddr);

    ICC_DEBUG("sending Msg_Publish_OK, peer: %s", peerAddr.toString().c_str());
    result = MsgProtocol::send(&this->getStream(), &os);
    delete msg;
    msg = 0;
    return result;
  }

  assert(msg->messageType == Msg_Event);
  assert(msg->topic != "");

  // print log , temporary variable "type" is for info,
  string type;
  InputStream is(msg->is);
  is.read_string(type);
  ICC_DEBUG("recved publish event, topic: %s, type: %s", msg->topic.c_str(), type.c_str());

  if(SubscriberHandler::enableBuffering) {
    TopicManager::instance()->addMessage_(msg);
  } else {
    TopicManager::instance()->addMessage(msg, SubscriberHandler::enableBuffering);
  }
  msg = 0;

  return result;
}