OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef REMOTING_JINGLE_GLUE_NETWORK_SETTINGS_H_ | 5 #ifndef REMOTING_JINGLE_GLUE_NETWORK_SETTINGS_H_ |
6 #define REMOTING_JINGLE_GLUE_NETWORK_SETTINGS_H_ | 6 #define REMOTING_JINGLE_GLUE_NETWORK_SETTINGS_H_ |
7 | 7 |
8 #include <string> | |
9 | |
10 #include "base/basictypes.h" | |
11 | |
8 namespace remoting { | 12 namespace remoting { |
9 | 13 |
10 struct NetworkSettings { | 14 struct NetworkSettings { |
11 | 15 |
12 // When hosts are configured with NAT traversal disabled they will | 16 // When hosts are configured with NAT traversal disabled they will |
13 // typically also limit their P2P ports to this range, so that | 17 // typically also limit their P2P ports to this range, so that |
14 // sessions may be blocked or un-blocked via firewall rules. | 18 // sessions may be blocked or un-blocked via firewall rules. |
15 static const int kDefaultMinPort = 12400; | 19 static const int kDefaultMinPort = 12400; |
16 static const int kDefaultMaxPort = 12409; | 20 static const int kDefaultMaxPort = 12409; |
17 | 21 |
18 enum NatTraversalMode { | 22 // Flags: |
Sergey Ulanov
2014/03/27 18:31:20
Define the flags in an enum instead of as a set of
dcaiafa
2014/03/27 19:32:24
Done.
| |
19 // Active NAT traversal using STUN and relay servers. | |
20 NAT_TRAVERSAL_ENABLED, | |
21 | 23 |
22 // Don't use STUN or relay servers. Accept incoming P2P connection | 24 // Don't use STUN or relay servers. Accept incoming P2P connection |
23 // attempts, but don't initiate any. This ensures that the peer is | 25 // attempts, but don't initiate any. This ensures that the peer is |
24 // on the same network. Note that connection will always fail if | 26 // on the same network. Note that connection will always fail if |
25 // both ends use this mode. | 27 // both ends use this mode. |
26 NAT_TRAVERSAL_DISABLED, | 28 static const uint32 NAT_TRAVERSAL_DISABLED = 0x0; |
27 | 29 |
28 // Don't use STUN or relay servers but make outgoing connections. | 30 // Active NAT traversal using STUN. |
29 NAT_TRAVERSAL_OUTGOING, | 31 static const uint32 NAT_TRAVERSAL_STUN = 0x1; |
30 }; | 32 |
33 // Allow the use of relay servers when a direct connection is not available. | |
34 static const uint32 NAT_TRAVERSAL_RELAY = 0x2; | |
35 | |
36 // Allow outgoing connections, even when STUN and RELAY are not enabled. | |
37 static const uint32 NAT_TRAVERSAL_OUTGOING = 0x4; | |
38 | |
39 // Active NAT traversal using STUN and relay servers. | |
40 static const uint32 NAT_TRAVERSAL_FULL = | |
41 NAT_TRAVERSAL_STUN | NAT_TRAVERSAL_RELAY; | |
Sergey Ulanov
2014/03/27 18:31:20
Should this also include NAT_TRAVERSAL_OUTGOING? o
dcaiafa
2014/03/27 19:32:24
What do you think of this?
| |
31 | 42 |
32 NetworkSettings() | 43 NetworkSettings() |
33 : nat_traversal_mode(NAT_TRAVERSAL_DISABLED), | 44 : flags(NAT_TRAVERSAL_DISABLED), |
34 min_port(0), | 45 min_port(0), |
35 max_port(0) { | 46 max_port(0) { |
36 } | 47 } |
37 | 48 |
38 explicit NetworkSettings(NatTraversalMode nat_traversal_mode) | 49 explicit NetworkSettings(uint32 flags) |
39 : nat_traversal_mode(nat_traversal_mode), | 50 : flags(flags), |
40 min_port(0), | 51 min_port(0), |
41 max_port(0) { | 52 max_port(0) { |
42 } | 53 } |
43 | 54 |
44 NatTraversalMode nat_traversal_mode; | 55 uint32 flags; |
45 | 56 |
46 // |min_port| and |max_port| specify range (inclusive) of ports used by | 57 // |min_port| and |max_port| specify range (inclusive) of ports used by |
47 // P2P sessions. Any port can be used when both values are set to 0. | 58 // P2P sessions. Any port can be used when both values are set to 0. |
48 int min_port; | 59 int min_port; |
49 int max_port; | 60 int max_port; |
50 }; | 61 }; |
51 | 62 |
63 // Parse string in the form "<min_port>-<max_port>". E.g. "12400-12409". | |
64 // Returns true if string was parsed successfuly. | |
65 bool ParsePortRange(const std::string& port_range, | |
Sergey Ulanov
2014/03/27 18:31:20
Make this a static method in NetworkSettings class
dcaiafa
2014/03/27 19:32:24
Done.
| |
66 int* out_min_port, | |
67 int* out_max_port); | |
68 | |
52 } // namespace remoting | 69 } // namespace remoting |
53 | 70 |
54 #endif // REMOTING_HOST_NETWORK_SETTINGS_H_ | 71 #endif // REMOTING_HOST_NETWORK_SETTINGS_H_ |
OLD | NEW |