Beispiel #1
0
void Mixer::remoteStartTransmission(const ::Ice::Current& curr) {
	stringstream a;
	stringstream b;
	LOG4CXX_DEBUG(logger, string("Mixer::remoteStartTransmission()"));

	IPV4Address *tmpAddr = new IPV4Address(getRemoteAddressFromConnection(curr.con));
	a << string("Mixer::remoteStartTransmission() rem hostAddr: ") << tmpAddr->getHostname();
	LOG4CXX_DEBUG(logger, a.str());

	TerminalInfo *info = remoteHostsM[tmpAddr->getHostname()];
	if (remoteHostsM.find(tmpAddr->getHostname()) == remoteHostsM.end()  ) {
		cout << "ERROR info not found\n";
	}

	if (this->currentState != States::PASSIVE_CONNECTED) {
		LOG4CXX_DEBUG(logger, string("Mixer::remoteStartTransmission() bad state"));
	} else {
		changeState(States::PASSIVE_OPERATIONAL);

		cout << "TRANSCEIVER STARTED\n";

		// TODO start RTP.RTCP transmission
		CodecFactory codecfactory;
		Codec* codecInc = codecfactory.getCodec(AudioCodec::PCMU); // HACK
		// 		Codec* codecInc = codecfactory.getCodec(info->incomingCodec);
		Codec* codecOut = codecfactory.getCodec(AudioCodec::PCMU);
		//		Codec* codecOut = codecfactory.getCodec(info->outgoingCodec); // HACK

		info->transport = new TransportCCRTP();
		info->transport->setParams(codecInc->getFrameCount(), codecInc->getFrameSize());
		info->transport->setLocalEndpoint("0.0.0.0", localRTPPort);
		info->transport->setRemoteEndpoint(info->address, info->rtpPort);
		info->buf = new RingBuffer(1024*1024, 1);
		// 		b << "Mixer::remoteStartTransmission() creating transport,
		localRTPPort += 2;

		stringstream a;
		a << "rem address: " << info->address << " port: " << info->rtpPort;
		LOG4CXX_DEBUG(logger, a.str());

		info->transport->start();

		LOG4CXX_DEBUG(logger, string("Mixer::remoteStartTransmission() transmission started"));
	}
}
Beispiel #2
0
/*
 * Leave a multicast group
 * @param group the address of the group to join
 * @return true if it worked, false otherwise
 */
bool UdpSocket::LeaveMulticast(const IPV4Address &iface,
                               const IPV4Address &group) {
  struct ip_mreq mreq;
  mreq.imr_interface = iface.Address();
  mreq.imr_multiaddr = group.Address();

  int ok = setsockopt(m_fd,
                      IPPROTO_IP,
                      IP_DROP_MEMBERSHIP,
                      reinterpret_cast<char*>(&mreq),
                      sizeof(mreq));
  if (ok < 0) {
    OLA_WARN << "Failed to leave multicast group " << group <<
    ": " << strerror(errno);
    return false;
  }
  return true;
}
Beispiel #3
0
/**
 * Handle a netlink message. If this message is a routing table message and it
 * contains the default route, then either:
 *   i) default_gateway is updated with the address of the gateway.
 *   ii) if_index is updated with the interface index for the default route.
 * @param if_index[out] possibly updated with interface index for the default
 *   route.
 * @param default_gateway[out] possibly updated with the default gateway.
 * @param nl_hdr the netlink message.
 */
void MessageHandler(int32_t *if_index,
                    IPV4Address *default_gateway,
                    const struct nlmsghdr *nl_hdr) {
  // Unless RTA_DST is provided, an RTA_GATEWAY or RTA_OIF attribute implies
  // it's the default route.
  IPV4Address gateway;
  int32_t index = Interface::DEFAULT_INDEX;

  bool is_default_route = true;

  // Loop over the attributes looking for RTA_GATEWAY and/or RTA_DST
  const rtmsg *rt_msg = reinterpret_cast<const rtmsg*>(NLMSG_DATA(nl_hdr));
  if (rt_msg->rtm_family == AF_INET && rt_msg->rtm_table == RT_TABLE_MAIN) {
    int rt_len = RTM_PAYLOAD(nl_hdr);

    for (const rtattr* rt_attr = reinterpret_cast<const rtattr*>(
            RTM_RTA(rt_msg));
         RTA_OK(rt_attr, rt_len);
         rt_attr = RTA_NEXT(rt_attr, rt_len)) {
      switch (rt_attr->rta_type) {
        case RTA_OIF:
          index = *(reinterpret_cast<int32_t*>(RTA_DATA(rt_attr)));
          break;
        case RTA_GATEWAY:
          gateway = IPV4Address(
              reinterpret_cast<const in_addr*>(RTA_DATA(rt_attr))->s_addr);
          break;
        case RTA_DST:
          IPV4Address dest(
              reinterpret_cast<const in_addr*>(RTA_DATA(rt_attr))->s_addr);
          is_default_route = dest.IsWildcard();
          break;
      }
    }
  }

  if (is_default_route &&
      (!gateway.IsWildcard() || index != Interface::DEFAULT_INDEX)) {
    *default_gateway = gateway;
    *if_index = index;
  }
}
Beispiel #4
0
bool UDPSocket::LeaveMulticast(const IPV4Address &iface,
                               const IPV4Address &group) {
  struct ip_mreq mreq;
  mreq.imr_interface.s_addr = iface.AsInt();
  mreq.imr_multiaddr.s_addr = group.AsInt();

#ifdef _WIN32
  int ok = setsockopt(m_handle.m_handle.m_fd,
#else
  int ok = setsockopt(m_handle,
#endif  // _WIN32
                      IPPROTO_IP,
                      IP_DROP_MEMBERSHIP,
                      reinterpret_cast<char*>(&mreq),
                      sizeof(mreq));
  if (ok < 0) {
    OLA_WARN << "Failed to leave multicast group " << group <<
    ": " << strerror(errno);
    return false;
  }
  return true;
}
Beispiel #5
0
Socket::Error UDPTransmit::cConnect(const IPV4Address &ia, tpport_t port)
{
    int len = sizeof(peer.ipv4);

    peer.ipv4.sin_family = AF_INET;
    peer.ipv4.sin_addr = ia.getAddress();
    peer.ipv4.sin_port = htons(port);
    // Win32 will crash if you try to connect to INADDR_ANY.
    if ( INADDR_ANY == peer.ipv4.sin_addr.s_addr )
        peer.ipv4.sin_addr.s_addr = INADDR_LOOPBACK;
    if(::connect(so, (sockaddr *)&peer.ipv4, len))
        return connectError();
    return errSuccess;
}
Beispiel #6
0
UDPSocket::UDPSocket(const IPV4Address &ia, tpport_t port) :
Socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP), family(IPV4), peer(ia.getAddress(), port)
{
#if defined(SO_REUSEADDR)
    int opt = 1;
    setsockopt(so, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, (socklen_t)sizeof(opt));
#endif
    if(bind(so, peer, sizeof(sockaddr_in))) {
        endSocket();
        error(errBindingFailed,(char *)"Could not bind socket",socket_errno);
        return;
    }
    state = BOUND;
}
Beispiel #7
0
void Tracker::connect(IPV4Address addr) try {
	logMsg(
		boost::format("[%s] Connecting to tracker %s[%s]:%d...")
		% getName() % m_host % addr.getAddrStr() % m_port
	);
	m_socket.reset(new TcpSocket(this, &Tracker::onSocketEvent));
	m_socket->connect(addr);
} catch (std::exception &e) {
	logError(
		boost::format("[%s] Error connecting to tracker[%s]: %s")
		% getName() % m_host % e.what()
	);
	onSocketEvent(m_socket.get(), SOCK_ERR);
}
Beispiel #8
0
void Mixer::remoteTryConnect(const ::agh::CallParameters& params, const ::Ice::Identity& ident, const ::Ice::Current& curr) {
	stringstream a;
	LOG4CXX_DEBUG(logger, string("Mixer::remoteTryConnect()"));
	masterCallbackPrx = IMasterCallbackPrx::uncheckedCast(curr.con->createProxy(ident));

	if (localAddr) {
		delete localAddr;
	}
	if (remoteAddr) {
		delete remoteAddr;
	}

	IPV4Address *tmpAddr = new IPV4Address(getRemoteAddressFromConnection(curr.con));
	TerminalInfo *info = new TerminalInfo;
	info->address = *tmpAddr;
	info->rtpPort = params.masterRtpPort;
	info->outgoingCodec = params.outgoingCodec.id;
	info->incomingCodec = params.incomingCodec.id;
	info->transport = NULL;
	info->readedSize = 0;
	info->buf = NULL;
	remoteHostsM[tmpAddr->getHostname()] = info;
	a << "Mixer::remoteTryConnect() conf received, remote addr: " << tmpAddr << " port: " << params.masterRtpPort;
	LOG4CXX_DEBUG(logger, a.str());

	changeState(States::PASSIVE_CONNECTED);

	// inform remote site
	LOG4CXX_DEBUG(logger, string("Mixer::remoteTryConnect() sending ACK..."));
	CallParametersResponse response;
	response.slaveRtpPort = localRTPPort;

	// Response in new thread
	WorkerThread* tmpThread = new WorkerThread(this, response);
	tmpThread->start();
	LOG4CXX_DEBUG(logger, string("Mixer::remoteTryConnect() ACK has been sent"));
}
Beispiel #9
0
UDPSocket::UDPSocket(const IPV4Address &ia, tpport_t port) :
Socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
{
    family = IPV4;
    memset(&peer.ipv4, 0, sizeof(peer));
    peer.ipv4.sin_family = AF_INET;
    peer.ipv4.sin_addr = ia.getAddress();
    peer.ipv4.sin_port = htons(port);
#if defined(SO_REUSEADDR)
    int opt = 1;
    setsockopt(so, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, (socklen_t)sizeof(opt));
#endif
    if(bind(so, (struct sockaddr *)&peer.ipv4, sizeof(peer.ipv4))) {
        endSocket();
        error(errBindingFailed,(char *)"Could not bind socket",socket_errno);
        return;
    }
    state = BOUND;
}
Beispiel #10
0
Socket::Error UDPTransmit::cConnect(const IPV4Address &ia, tpport_t port)
{
    return connect(ucommon::Socket::address(ia.getAddress(), port));
}
bool IPV4Address::operator==(const IPV4Address & a) const
{
	return host_==a.host() && port_==a.port();
}