2014-05-13 18:00:26 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright 2004 The WebRTC Project Authors. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef WEBRTC_BASE_NETWORK_H_
|
|
|
|
|
#define WEBRTC_BASE_NETWORK_H_
|
|
|
|
|
|
|
|
|
|
#include <deque>
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "webrtc/base/basictypes.h"
|
|
|
|
|
#include "webrtc/base/ipaddress.h"
|
|
|
|
|
#include "webrtc/base/messagehandler.h"
|
2015-02-18 18:44:01 +00:00
|
|
|
#include "webrtc/base/scoped_ptr.h"
|
2014-05-13 18:00:26 +00:00
|
|
|
#include "webrtc/base/sigslot.h"
|
|
|
|
|
|
|
|
|
|
#if defined(WEBRTC_POSIX)
|
|
|
|
|
struct ifaddrs;
|
|
|
|
|
#endif // defined(WEBRTC_POSIX)
|
|
|
|
|
|
|
|
|
|
namespace rtc {
|
|
|
|
|
|
|
|
|
|
class Network;
|
|
|
|
|
class Thread;
|
|
|
|
|
|
|
|
|
|
enum AdapterType {
|
|
|
|
|
// This enum resembles the one in Chromium net::ConnectionType.
|
|
|
|
|
ADAPTER_TYPE_UNKNOWN = 0,
|
Makes libjingle_peerconnection_android_unittest run on networkless devices.
PeerConnectionTest.java currently works, but only on a device with
network interfaces up. This is not a problem for desktop, but it is a
problem when running on Android devices since the devices in the lab
generally don't have network (due to the chaotic radio environment in
the device labs, devices are simply kept in flight mode).
The test does work if one modifies this line in the file
webrtc/base/network.cc:
bool ignored = ((cursor->ifa_flags & IFF_LOOPBACK) ||
IsIgnoredNetwork(*network));
If we remove the IFF_LOOPBACK clause, the test starts working on
an Android device in flight mode. This is nice - we're running the
call and packets interact with the OS network stack, which is good
for this end-to-end test. We can't just remove the clause though since
having loopback is undesirable for everyone except the test (right)?
so we need to make this behavior configurable.
This CL takes a stab at a complete solution where we pass a boolean
all the way through the Java PeerConnectionFactory down to the
BasicNetworkManager. This comes as a heavy price in interface
changes though. It's pretty out of proportion, but fundamentally we
need some way of telling the network manager that it is on Android
and in test mode. Passing the boolean all the way through is one way.
Another way might be to put the loopback filter behind an ifdef and
link a custom libjingle_peerconnection.so with the test. That is hacky
but doesn't pollute the interfaces. Not sure how to solve that in GYP
but it could mean some duplication between the production and
test .so files.
It would have been perfect to use flags here, but then we need to
hook up gflags parsing to some main() somewhere to make sure the
flag gets parsed, and make sure to pass that flag in our tests.
I'm not sure how that can be done.
Making the loopback filtering conditional is exactly how we solved the
equivalent problem in content_browsertests in Chrome, and it worked
great.
That's all I could think of.
BUG=4181
R=perkj@webrtc.org, pthatcher@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/36769004
Cr-Commit-Position: refs/heads/master@{#8344}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8344 4adac7df-926f-26a2-2b94-8c16560cd09d
2015-02-12 09:23:59 +00:00
|
|
|
ADAPTER_TYPE_ETHERNET = 1 << 0,
|
|
|
|
|
ADAPTER_TYPE_WIFI = 1 << 1,
|
|
|
|
|
ADAPTER_TYPE_CELLULAR = 1 << 2,
|
|
|
|
|
ADAPTER_TYPE_VPN = 1 << 3,
|
|
|
|
|
ADAPTER_TYPE_LOOPBACK = 1 << 4
|
2014-05-13 18:00:26 +00:00
|
|
|
};
|
|
|
|
|
|
Makes libjingle_peerconnection_android_unittest run on networkless devices.
PeerConnectionTest.java currently works, but only on a device with
network interfaces up. This is not a problem for desktop, but it is a
problem when running on Android devices since the devices in the lab
generally don't have network (due to the chaotic radio environment in
the device labs, devices are simply kept in flight mode).
The test does work if one modifies this line in the file
webrtc/base/network.cc:
bool ignored = ((cursor->ifa_flags & IFF_LOOPBACK) ||
IsIgnoredNetwork(*network));
If we remove the IFF_LOOPBACK clause, the test starts working on
an Android device in flight mode. This is nice - we're running the
call and packets interact with the OS network stack, which is good
for this end-to-end test. We can't just remove the clause though since
having loopback is undesirable for everyone except the test (right)?
so we need to make this behavior configurable.
This CL takes a stab at a complete solution where we pass a boolean
all the way through the Java PeerConnectionFactory down to the
BasicNetworkManager. This comes as a heavy price in interface
changes though. It's pretty out of proportion, but fundamentally we
need some way of telling the network manager that it is on Android
and in test mode. Passing the boolean all the way through is one way.
Another way might be to put the loopback filter behind an ifdef and
link a custom libjingle_peerconnection.so with the test. That is hacky
but doesn't pollute the interfaces. Not sure how to solve that in GYP
but it could mean some duplication between the production and
test .so files.
It would have been perfect to use flags here, but then we need to
hook up gflags parsing to some main() somewhere to make sure the
flag gets parsed, and make sure to pass that flag in our tests.
I'm not sure how that can be done.
Making the loopback filtering conditional is exactly how we solved the
equivalent problem in content_browsertests in Chrome, and it worked
great.
That's all I could think of.
BUG=4181
R=perkj@webrtc.org, pthatcher@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/36769004
Cr-Commit-Position: refs/heads/master@{#8344}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8344 4adac7df-926f-26a2-2b94-8c16560cd09d
2015-02-12 09:23:59 +00:00
|
|
|
// By default, ignore loopback interfaces on the host.
|
|
|
|
|
const int kDefaultNetworkIgnoreMask = ADAPTER_TYPE_LOOPBACK;
|
|
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
// Makes a string key for this network. Used in the network manager's maps.
|
|
|
|
|
// Network objects are keyed on interface name, network prefix and the
|
|
|
|
|
// length of that prefix.
|
|
|
|
|
std::string MakeNetworkKey(const std::string& name, const IPAddress& prefix,
|
|
|
|
|
int prefix_length);
|
|
|
|
|
|
|
|
|
|
// Generic network manager interface. It provides list of local
|
|
|
|
|
// networks.
|
|
|
|
|
class NetworkManager {
|
|
|
|
|
public:
|
|
|
|
|
typedef std::vector<Network*> NetworkList;
|
|
|
|
|
|
|
|
|
|
NetworkManager();
|
|
|
|
|
virtual ~NetworkManager();
|
|
|
|
|
|
|
|
|
|
// Called when network list is updated.
|
|
|
|
|
sigslot::signal0<> SignalNetworksChanged;
|
|
|
|
|
|
|
|
|
|
// Indicates a failure when getting list of network interfaces.
|
|
|
|
|
sigslot::signal0<> SignalError;
|
|
|
|
|
|
|
|
|
|
// Start/Stop monitoring of network interfaces
|
Makes libjingle_peerconnection_android_unittest run on networkless devices.
PeerConnectionTest.java currently works, but only on a device with
network interfaces up. This is not a problem for desktop, but it is a
problem when running on Android devices since the devices in the lab
generally don't have network (due to the chaotic radio environment in
the device labs, devices are simply kept in flight mode).
The test does work if one modifies this line in the file
webrtc/base/network.cc:
bool ignored = ((cursor->ifa_flags & IFF_LOOPBACK) ||
IsIgnoredNetwork(*network));
If we remove the IFF_LOOPBACK clause, the test starts working on
an Android device in flight mode. This is nice - we're running the
call and packets interact with the OS network stack, which is good
for this end-to-end test. We can't just remove the clause though since
having loopback is undesirable for everyone except the test (right)?
so we need to make this behavior configurable.
This CL takes a stab at a complete solution where we pass a boolean
all the way through the Java PeerConnectionFactory down to the
BasicNetworkManager. This comes as a heavy price in interface
changes though. It's pretty out of proportion, but fundamentally we
need some way of telling the network manager that it is on Android
and in test mode. Passing the boolean all the way through is one way.
Another way might be to put the loopback filter behind an ifdef and
link a custom libjingle_peerconnection.so with the test. That is hacky
but doesn't pollute the interfaces. Not sure how to solve that in GYP
but it could mean some duplication between the production and
test .so files.
It would have been perfect to use flags here, but then we need to
hook up gflags parsing to some main() somewhere to make sure the
flag gets parsed, and make sure to pass that flag in our tests.
I'm not sure how that can be done.
Making the loopback filtering conditional is exactly how we solved the
equivalent problem in content_browsertests in Chrome, and it worked
great.
That's all I could think of.
BUG=4181
R=perkj@webrtc.org, pthatcher@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/36769004
Cr-Commit-Position: refs/heads/master@{#8344}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8344 4adac7df-926f-26a2-2b94-8c16560cd09d
2015-02-12 09:23:59 +00:00
|
|
|
// list. SignalNetworksChanged or SignalError is emitted immediately
|
2014-05-13 18:00:26 +00:00
|
|
|
// after StartUpdating() is called. After that SignalNetworksChanged
|
Makes libjingle_peerconnection_android_unittest run on networkless devices.
PeerConnectionTest.java currently works, but only on a device with
network interfaces up. This is not a problem for desktop, but it is a
problem when running on Android devices since the devices in the lab
generally don't have network (due to the chaotic radio environment in
the device labs, devices are simply kept in flight mode).
The test does work if one modifies this line in the file
webrtc/base/network.cc:
bool ignored = ((cursor->ifa_flags & IFF_LOOPBACK) ||
IsIgnoredNetwork(*network));
If we remove the IFF_LOOPBACK clause, the test starts working on
an Android device in flight mode. This is nice - we're running the
call and packets interact with the OS network stack, which is good
for this end-to-end test. We can't just remove the clause though since
having loopback is undesirable for everyone except the test (right)?
so we need to make this behavior configurable.
This CL takes a stab at a complete solution where we pass a boolean
all the way through the Java PeerConnectionFactory down to the
BasicNetworkManager. This comes as a heavy price in interface
changes though. It's pretty out of proportion, but fundamentally we
need some way of telling the network manager that it is on Android
and in test mode. Passing the boolean all the way through is one way.
Another way might be to put the loopback filter behind an ifdef and
link a custom libjingle_peerconnection.so with the test. That is hacky
but doesn't pollute the interfaces. Not sure how to solve that in GYP
but it could mean some duplication between the production and
test .so files.
It would have been perfect to use flags here, but then we need to
hook up gflags parsing to some main() somewhere to make sure the
flag gets parsed, and make sure to pass that flag in our tests.
I'm not sure how that can be done.
Making the loopback filtering conditional is exactly how we solved the
equivalent problem in content_browsertests in Chrome, and it worked
great.
That's all I could think of.
BUG=4181
R=perkj@webrtc.org, pthatcher@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/36769004
Cr-Commit-Position: refs/heads/master@{#8344}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8344 4adac7df-926f-26a2-2b94-8c16560cd09d
2015-02-12 09:23:59 +00:00
|
|
|
// is emitted whenever list of networks changes.
|
2014-05-13 18:00:26 +00:00
|
|
|
virtual void StartUpdating() = 0;
|
|
|
|
|
virtual void StopUpdating() = 0;
|
|
|
|
|
|
|
|
|
|
// Returns the current list of networks available on this machine.
|
|
|
|
|
// UpdateNetworks() must be called before this method is called.
|
|
|
|
|
// It makes sure that repeated calls return the same object for a
|
|
|
|
|
// given network, so that quality is tracked appropriately. Does not
|
|
|
|
|
// include ignored networks.
|
|
|
|
|
virtual void GetNetworks(NetworkList* networks) const = 0;
|
|
|
|
|
|
2015-02-18 18:44:01 +00:00
|
|
|
// "AnyAddressNetwork" is a network which only contains single "any address"
|
|
|
|
|
// IP address. (i.e. INADDR_ANY for IPv4 or in6addr_any for IPv6). This is
|
|
|
|
|
// useful as binding to such interfaces allow default routing behavior like
|
|
|
|
|
// http traffic.
|
|
|
|
|
virtual void GetAnyAddressNetworks(NetworkList* networks) = 0;
|
|
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
// Dumps a list of networks available to LS_INFO.
|
|
|
|
|
virtual void DumpNetworks(bool include_ignored) {}
|
2015-01-28 19:34:05 +00:00
|
|
|
|
|
|
|
|
struct Stats {
|
|
|
|
|
int ipv4_network_count;
|
|
|
|
|
int ipv6_network_count;
|
|
|
|
|
Stats() {
|
|
|
|
|
ipv4_network_count = 0;
|
|
|
|
|
ipv6_network_count = 0;
|
|
|
|
|
}
|
|
|
|
|
};
|
2014-05-13 18:00:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Base class for NetworkManager implementations.
|
|
|
|
|
class NetworkManagerBase : public NetworkManager {
|
|
|
|
|
public:
|
|
|
|
|
NetworkManagerBase();
|
|
|
|
|
virtual ~NetworkManagerBase();
|
|
|
|
|
|
|
|
|
|
virtual void GetNetworks(std::vector<Network*>* networks) const;
|
2015-02-18 18:44:01 +00:00
|
|
|
virtual void GetAnyAddressNetworks(NetworkList* networks);
|
2014-05-13 18:00:26 +00:00
|
|
|
bool ipv6_enabled() const { return ipv6_enabled_; }
|
|
|
|
|
void set_ipv6_enabled(bool enabled) { ipv6_enabled_ = enabled; }
|
|
|
|
|
|
2015-01-30 00:09:28 +00:00
|
|
|
void set_max_ipv6_networks(int networks) { max_ipv6_networks_ = networks; }
|
|
|
|
|
int max_ipv6_networks() { return max_ipv6_networks_; }
|
|
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
protected:
|
|
|
|
|
typedef std::map<std::string, Network*> NetworkMap;
|
|
|
|
|
// Updates |networks_| with the networks listed in |list|. If
|
|
|
|
|
// |network_map_| already has a Network object for a network listed
|
|
|
|
|
// in the |list| then it is reused. Accept ownership of the Network
|
|
|
|
|
// objects in the |list|. |changed| will be set to true if there is
|
|
|
|
|
// any change in the network list.
|
|
|
|
|
void MergeNetworkList(const NetworkList& list, bool* changed);
|
|
|
|
|
|
2015-01-28 19:34:05 +00:00
|
|
|
// |stats| will be populated even if |*changed| is false.
|
|
|
|
|
void MergeNetworkList(const NetworkList& list,
|
|
|
|
|
bool* changed,
|
|
|
|
|
NetworkManager::Stats* stats);
|
|
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
private:
|
|
|
|
|
friend class NetworkTest;
|
|
|
|
|
void DoUpdateNetworks();
|
|
|
|
|
|
|
|
|
|
NetworkList networks_;
|
2015-01-30 00:09:28 +00:00
|
|
|
int max_ipv6_networks_;
|
|
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
NetworkMap networks_map_;
|
|
|
|
|
bool ipv6_enabled_;
|
2015-02-18 18:44:01 +00:00
|
|
|
|
|
|
|
|
rtc::scoped_ptr<rtc::Network> ipv4_any_address_network_;
|
|
|
|
|
rtc::scoped_ptr<rtc::Network> ipv6_any_address_network_;
|
2014-05-13 18:00:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Basic implementation of the NetworkManager interface that gets list
|
|
|
|
|
// of networks using OS APIs.
|
|
|
|
|
class BasicNetworkManager : public NetworkManagerBase,
|
|
|
|
|
public MessageHandler {
|
|
|
|
|
public:
|
|
|
|
|
BasicNetworkManager();
|
|
|
|
|
virtual ~BasicNetworkManager();
|
|
|
|
|
|
|
|
|
|
virtual void StartUpdating();
|
|
|
|
|
virtual void StopUpdating();
|
|
|
|
|
|
|
|
|
|
// Logs the available networks.
|
|
|
|
|
virtual void DumpNetworks(bool include_ignored);
|
|
|
|
|
|
|
|
|
|
// MessageHandler interface.
|
|
|
|
|
virtual void OnMessage(Message* msg);
|
|
|
|
|
bool started() { return start_count_ > 0; }
|
|
|
|
|
|
Makes libjingle_peerconnection_android_unittest run on networkless devices.
PeerConnectionTest.java currently works, but only on a device with
network interfaces up. This is not a problem for desktop, but it is a
problem when running on Android devices since the devices in the lab
generally don't have network (due to the chaotic radio environment in
the device labs, devices are simply kept in flight mode).
The test does work if one modifies this line in the file
webrtc/base/network.cc:
bool ignored = ((cursor->ifa_flags & IFF_LOOPBACK) ||
IsIgnoredNetwork(*network));
If we remove the IFF_LOOPBACK clause, the test starts working on
an Android device in flight mode. This is nice - we're running the
call and packets interact with the OS network stack, which is good
for this end-to-end test. We can't just remove the clause though since
having loopback is undesirable for everyone except the test (right)?
so we need to make this behavior configurable.
This CL takes a stab at a complete solution where we pass a boolean
all the way through the Java PeerConnectionFactory down to the
BasicNetworkManager. This comes as a heavy price in interface
changes though. It's pretty out of proportion, but fundamentally we
need some way of telling the network manager that it is on Android
and in test mode. Passing the boolean all the way through is one way.
Another way might be to put the loopback filter behind an ifdef and
link a custom libjingle_peerconnection.so with the test. That is hacky
but doesn't pollute the interfaces. Not sure how to solve that in GYP
but it could mean some duplication between the production and
test .so files.
It would have been perfect to use flags here, but then we need to
hook up gflags parsing to some main() somewhere to make sure the
flag gets parsed, and make sure to pass that flag in our tests.
I'm not sure how that can be done.
Making the loopback filtering conditional is exactly how we solved the
equivalent problem in content_browsertests in Chrome, and it worked
great.
That's all I could think of.
BUG=4181
R=perkj@webrtc.org, pthatcher@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/36769004
Cr-Commit-Position: refs/heads/master@{#8344}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8344 4adac7df-926f-26a2-2b94-8c16560cd09d
2015-02-12 09:23:59 +00:00
|
|
|
// Sets the network ignore list, which is empty by default. Any network on the
|
|
|
|
|
// ignore list will be filtered from network enumeration results.
|
2014-05-13 18:00:26 +00:00
|
|
|
void set_network_ignore_list(const std::vector<std::string>& list) {
|
|
|
|
|
network_ignore_list_ = list;
|
|
|
|
|
}
|
Makes libjingle_peerconnection_android_unittest run on networkless devices.
PeerConnectionTest.java currently works, but only on a device with
network interfaces up. This is not a problem for desktop, but it is a
problem when running on Android devices since the devices in the lab
generally don't have network (due to the chaotic radio environment in
the device labs, devices are simply kept in flight mode).
The test does work if one modifies this line in the file
webrtc/base/network.cc:
bool ignored = ((cursor->ifa_flags & IFF_LOOPBACK) ||
IsIgnoredNetwork(*network));
If we remove the IFF_LOOPBACK clause, the test starts working on
an Android device in flight mode. This is nice - we're running the
call and packets interact with the OS network stack, which is good
for this end-to-end test. We can't just remove the clause though since
having loopback is undesirable for everyone except the test (right)?
so we need to make this behavior configurable.
This CL takes a stab at a complete solution where we pass a boolean
all the way through the Java PeerConnectionFactory down to the
BasicNetworkManager. This comes as a heavy price in interface
changes though. It's pretty out of proportion, but fundamentally we
need some way of telling the network manager that it is on Android
and in test mode. Passing the boolean all the way through is one way.
Another way might be to put the loopback filter behind an ifdef and
link a custom libjingle_peerconnection.so with the test. That is hacky
but doesn't pollute the interfaces. Not sure how to solve that in GYP
but it could mean some duplication between the production and
test .so files.
It would have been perfect to use flags here, but then we need to
hook up gflags parsing to some main() somewhere to make sure the
flag gets parsed, and make sure to pass that flag in our tests.
I'm not sure how that can be done.
Making the loopback filtering conditional is exactly how we solved the
equivalent problem in content_browsertests in Chrome, and it worked
great.
That's all I could think of.
BUG=4181
R=perkj@webrtc.org, pthatcher@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/36769004
Cr-Commit-Position: refs/heads/master@{#8344}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8344 4adac7df-926f-26a2-2b94-8c16560cd09d
2015-02-12 09:23:59 +00:00
|
|
|
|
|
|
|
|
// Sets the network types to ignore. For instance, calling this with
|
|
|
|
|
// ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and
|
|
|
|
|
// loopback interfaces. Set to kDefaultNetworkIgnoreMask by default.
|
|
|
|
|
void set_network_ignore_mask(int network_ignore_mask) {
|
|
|
|
|
// TODO(phoglund): implement support for other types than loopback.
|
|
|
|
|
// See https://code.google.com/p/webrtc/issues/detail?id=4288.
|
|
|
|
|
// Then remove set_network_ignore_list.
|
|
|
|
|
network_ignore_mask_ = network_ignore_mask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int network_ignore_mask() const { return network_ignore_mask_; }
|
|
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
#if defined(WEBRTC_LINUX)
|
|
|
|
|
// Sets the flag for ignoring non-default routes.
|
|
|
|
|
void set_ignore_non_default_routes(bool value) {
|
|
|
|
|
ignore_non_default_routes_ = true;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
#if defined(WEBRTC_POSIX)
|
|
|
|
|
// Separated from CreateNetworks for tests.
|
|
|
|
|
void ConvertIfAddrs(ifaddrs* interfaces,
|
|
|
|
|
bool include_ignored,
|
|
|
|
|
NetworkList* networks) const;
|
|
|
|
|
#endif // defined(WEBRTC_POSIX)
|
|
|
|
|
|
|
|
|
|
// Creates a network object for each network available on the machine.
|
|
|
|
|
bool CreateNetworks(bool include_ignored, NetworkList* networks) const;
|
|
|
|
|
|
|
|
|
|
// Determines if a network should be ignored.
|
|
|
|
|
bool IsIgnoredNetwork(const Network& network) const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
friend class NetworkTest;
|
|
|
|
|
|
|
|
|
|
void DoUpdateNetworks();
|
|
|
|
|
|
|
|
|
|
Thread* thread_;
|
|
|
|
|
bool sent_first_update_;
|
|
|
|
|
int start_count_;
|
|
|
|
|
std::vector<std::string> network_ignore_list_;
|
Makes libjingle_peerconnection_android_unittest run on networkless devices.
PeerConnectionTest.java currently works, but only on a device with
network interfaces up. This is not a problem for desktop, but it is a
problem when running on Android devices since the devices in the lab
generally don't have network (due to the chaotic radio environment in
the device labs, devices are simply kept in flight mode).
The test does work if one modifies this line in the file
webrtc/base/network.cc:
bool ignored = ((cursor->ifa_flags & IFF_LOOPBACK) ||
IsIgnoredNetwork(*network));
If we remove the IFF_LOOPBACK clause, the test starts working on
an Android device in flight mode. This is nice - we're running the
call and packets interact with the OS network stack, which is good
for this end-to-end test. We can't just remove the clause though since
having loopback is undesirable for everyone except the test (right)?
so we need to make this behavior configurable.
This CL takes a stab at a complete solution where we pass a boolean
all the way through the Java PeerConnectionFactory down to the
BasicNetworkManager. This comes as a heavy price in interface
changes though. It's pretty out of proportion, but fundamentally we
need some way of telling the network manager that it is on Android
and in test mode. Passing the boolean all the way through is one way.
Another way might be to put the loopback filter behind an ifdef and
link a custom libjingle_peerconnection.so with the test. That is hacky
but doesn't pollute the interfaces. Not sure how to solve that in GYP
but it could mean some duplication between the production and
test .so files.
It would have been perfect to use flags here, but then we need to
hook up gflags parsing to some main() somewhere to make sure the
flag gets parsed, and make sure to pass that flag in our tests.
I'm not sure how that can be done.
Making the loopback filtering conditional is exactly how we solved the
equivalent problem in content_browsertests in Chrome, and it worked
great.
That's all I could think of.
BUG=4181
R=perkj@webrtc.org, pthatcher@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/36769004
Cr-Commit-Position: refs/heads/master@{#8344}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8344 4adac7df-926f-26a2-2b94-8c16560cd09d
2015-02-12 09:23:59 +00:00
|
|
|
int network_ignore_mask_;
|
2014-05-13 18:00:26 +00:00
|
|
|
bool ignore_non_default_routes_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Represents a Unix-type network interface, with a name and single address.
|
|
|
|
|
class Network {
|
|
|
|
|
public:
|
|
|
|
|
Network(const std::string& name, const std::string& description,
|
|
|
|
|
const IPAddress& prefix, int prefix_length);
|
|
|
|
|
|
|
|
|
|
Network(const std::string& name, const std::string& description,
|
|
|
|
|
const IPAddress& prefix, int prefix_length, AdapterType type);
|
|
|
|
|
|
|
|
|
|
// Returns the name of the interface this network is associated wtih.
|
|
|
|
|
const std::string& name() const { return name_; }
|
|
|
|
|
|
|
|
|
|
// Returns the OS-assigned name for this network. This is useful for
|
|
|
|
|
// debugging but should not be sent over the wire (for privacy reasons).
|
|
|
|
|
const std::string& description() const { return description_; }
|
|
|
|
|
|
|
|
|
|
// Returns the prefix for this network.
|
|
|
|
|
const IPAddress& prefix() const { return prefix_; }
|
|
|
|
|
// Returns the length, in bits, of this network's prefix.
|
|
|
|
|
int prefix_length() const { return prefix_length_; }
|
|
|
|
|
|
|
|
|
|
// |key_| has unique value per network interface. Used in sorting network
|
|
|
|
|
// interfaces. Key is derived from interface name and it's prefix.
|
|
|
|
|
std::string key() const { return key_; }
|
|
|
|
|
|
|
|
|
|
// Returns the Network's current idea of the 'best' IP it has.
|
2014-09-17 22:37:29 +00:00
|
|
|
// Or return an unset IP if this network has no active addresses.
|
|
|
|
|
// Here is the rule on how we mark the IPv6 address as ignorable for WebRTC.
|
2014-09-09 23:42:40 +00:00
|
|
|
// 1) return all global temporary dynamic and non-deprecrated ones.
|
2014-09-17 22:37:29 +00:00
|
|
|
// 2) if #1 not available, return global ones.
|
|
|
|
|
// 3) if #2 not available, use ULA ipv6 as last resort. (ULA stands
|
|
|
|
|
// for unique local address, which is not route-able in open
|
|
|
|
|
// internet but might be useful for a close WebRTC deployment.
|
|
|
|
|
|
|
|
|
|
// TODO(guoweis): rule #3 actually won't happen at current
|
|
|
|
|
// implementation. The reason being that ULA address starting with
|
|
|
|
|
// 0xfc 0r 0xfd will be grouped into its own Network. The result of
|
|
|
|
|
// that is WebRTC will have one extra Network to generate candidates
|
|
|
|
|
// but the lack of rule #3 shouldn't prevent turning on IPv6 since
|
|
|
|
|
// ULA should only be tried in a close deployment anyway.
|
|
|
|
|
|
2014-09-09 23:42:40 +00:00
|
|
|
// Note that when not specifying any flag, it's treated as case global
|
2014-09-17 22:37:29 +00:00
|
|
|
// IPv6 address
|
|
|
|
|
IPAddress GetBestIP() const;
|
|
|
|
|
|
|
|
|
|
// Keep the original function here for now.
|
|
|
|
|
// TODO(guoweis): Remove this when all callers are migrated to GetBestIP().
|
|
|
|
|
IPAddress ip() const { return GetBestIP(); }
|
2014-09-09 23:42:40 +00:00
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
// Adds an active IP address to this network. Does not check for duplicates.
|
2014-09-09 23:42:40 +00:00
|
|
|
void AddIP(const InterfaceAddress& ip) { ips_.push_back(ip); }
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
// Sets the network's IP address list. Returns true if new IP addresses were
|
|
|
|
|
// detected. Passing true to already_changed skips this check.
|
2014-09-09 23:42:40 +00:00
|
|
|
bool SetIPs(const std::vector<InterfaceAddress>& ips, bool already_changed);
|
2014-05-13 18:00:26 +00:00
|
|
|
// Get the list of IP Addresses associated with this network.
|
2014-09-09 23:42:40 +00:00
|
|
|
const std::vector<InterfaceAddress>& GetIPs() const { return ips_;}
|
2014-05-13 18:00:26 +00:00
|
|
|
// Clear the network's list of addresses.
|
|
|
|
|
void ClearIPs() { ips_.clear(); }
|
|
|
|
|
|
|
|
|
|
// Returns the scope-id of the network's address.
|
|
|
|
|
// Should only be relevant for link-local IPv6 addresses.
|
|
|
|
|
int scope_id() const { return scope_id_; }
|
|
|
|
|
void set_scope_id(int id) { scope_id_ = id; }
|
|
|
|
|
|
|
|
|
|
// Indicates whether this network should be ignored, perhaps because
|
|
|
|
|
// the IP is 0, or the interface is one we know is invalid.
|
|
|
|
|
bool ignored() const { return ignored_; }
|
|
|
|
|
void set_ignored(bool ignored) { ignored_ = ignored; }
|
|
|
|
|
|
|
|
|
|
AdapterType type() const { return type_; }
|
|
|
|
|
int preference() const { return preference_; }
|
|
|
|
|
void set_preference(int preference) { preference_ = preference; }
|
|
|
|
|
|
|
|
|
|
// Debugging description of this network
|
|
|
|
|
std::string ToString() const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::string name_;
|
|
|
|
|
std::string description_;
|
|
|
|
|
IPAddress prefix_;
|
|
|
|
|
int prefix_length_;
|
|
|
|
|
std::string key_;
|
2014-09-09 23:42:40 +00:00
|
|
|
std::vector<InterfaceAddress> ips_;
|
2014-05-13 18:00:26 +00:00
|
|
|
int scope_id_;
|
|
|
|
|
bool ignored_;
|
|
|
|
|
AdapterType type_;
|
|
|
|
|
int preference_;
|
|
|
|
|
|
|
|
|
|
friend class NetworkManager;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace rtc
|
|
|
|
|
|
|
|
|
|
#endif // WEBRTC_BASE_NETWORK_H_
|