blob: fe6932037395879cd2db56f79a4c49e710251c35 [file] [log] [blame]
Robert Greenwalt9ba9c582014-03-19 17:56:12 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.net;
18
19import android.os.Parcelable;
20import android.os.Parcel;
Lorenzo Colitti9f1274b2014-08-21 11:45:54 -070021import android.system.ErrnoException;
Erik Klined8959992015-06-05 17:37:45 +090022import android.system.Os;
23import android.system.OsConstants;
Robert Greenwalt9ba9c582014-03-19 17:56:12 -070024
Sreeram Ramachandrane15db7c2014-10-22 11:10:20 -070025import java.io.FileDescriptor;
Paul Jensen2d6f2652014-05-20 11:25:35 -040026import java.io.IOException;
Sreeram Ramachandrane15db7c2014-10-22 11:10:20 -070027import java.net.DatagramSocket;
Paul Jensen3e32a4b2014-05-13 19:05:13 -040028import java.net.InetAddress;
Paul Jensen2d6f2652014-05-20 11:25:35 -040029import java.net.InetSocketAddress;
Lorenzo Colittic473dc42014-07-18 01:34:19 +090030import java.net.MalformedURLException;
Robert Greenwalt85956262014-05-18 20:29:39 -070031import java.net.Socket;
Lorenzo Colittif0382892014-07-30 17:17:13 +090032import java.net.SocketAddress;
Paul Jensen32a58f02014-06-20 13:58:14 -040033import java.net.SocketException;
Paul Jensen3e32a4b2014-05-13 19:05:13 -040034import java.net.UnknownHostException;
Lorenzo Colittic473dc42014-07-18 01:34:19 +090035import java.net.URL;
Lorenzo Colitti9f1274b2014-08-21 11:45:54 -070036import java.net.URLConnection;
Robert Greenwalt85956262014-05-18 20:29:39 -070037import javax.net.SocketFactory;
Robert Greenwalt9ba9c582014-03-19 17:56:12 -070038
Lorenzo Colitti0ed0a282014-08-28 17:15:40 -070039import com.android.okhttp.ConnectionPool;
Paul Jensen07ed0742014-09-08 14:59:09 -040040import com.android.okhttp.HttpHandler;
41import com.android.okhttp.HttpsHandler;
Lorenzo Colittic473dc42014-07-18 01:34:19 +090042import com.android.okhttp.OkHttpClient;
Neil Fuller50a01d82015-01-12 16:49:06 +000043import com.android.okhttp.OkUrlFactory;
44import com.android.okhttp.internal.Internal;
Lorenzo Colittic473dc42014-07-18 01:34:19 +090045
Robert Greenwalt9ba9c582014-03-19 17:56:12 -070046/**
Robert Greenwalt85956262014-05-18 20:29:39 -070047 * Identifies a {@code Network}. This is supplied to applications via
Robert Greenwalt6078b502014-06-11 16:05:07 -070048 * {@link ConnectivityManager.NetworkCallback} in response to the active
49 * {@link ConnectivityManager#requestNetwork} or passive
50 * {@link ConnectivityManager#registerNetworkCallback} calls.
Robert Greenwalt85956262014-05-18 20:29:39 -070051 * It is used to direct traffic to the given {@code Network}, either on a {@link Socket} basis
Paul Jensen0a363a32014-05-29 10:12:39 -040052 * through a targeted {@link SocketFactory} or process-wide via
Paul Jensen72db88e2015-03-10 10:54:12 -040053 * {@link ConnectivityManager#bindProcessToNetwork}.
Robert Greenwalt9ba9c582014-03-19 17:56:12 -070054 */
55public class Network implements Parcelable {
56
Robert Greenwalt85956262014-05-18 20:29:39 -070057 /**
58 * @hide
59 */
Robert Greenwalt9ba9c582014-03-19 17:56:12 -070060 public final int netId;
61
Lorenzo Colittic473dc42014-07-18 01:34:19 +090062 // Objects used to perform per-network operations such as getSocketFactory
Lorenzo Colitti9f1274b2014-08-21 11:45:54 -070063 // and openConnection, and a lock to protect access to them.
Lorenzo Colitti5b37fa22014-07-29 22:51:27 +090064 private volatile NetworkBoundSocketFactory mNetworkBoundSocketFactory = null;
Neil Fuller50a01d82015-01-12 16:49:06 +000065 // mLock should be used to control write access to mConnectionPool and mNetwork.
Paul Jensen07ed0742014-09-08 14:59:09 -040066 // maybeInitHttpClient() must be called prior to reading either variable.
67 private volatile ConnectionPool mConnectionPool = null;
Neil Fuller50a01d82015-01-12 16:49:06 +000068 private volatile com.android.okhttp.internal.Network mNetwork = null;
Erik Klined8959992015-06-05 17:37:45 +090069 private final Object mLock = new Object();
Paul Jensen2d6f2652014-05-20 11:25:35 -040070
Lorenzo Colitti0ed0a282014-08-28 17:15:40 -070071 // Default connection pool values. These are evaluated at startup, just
72 // like the OkHttp code. Also like the OkHttp code, we will throw parse
73 // exceptions at class loading time if the properties are set but are not
74 // valid integers.
75 private static final boolean httpKeepAlive =
76 Boolean.parseBoolean(System.getProperty("http.keepAlive", "true"));
77 private static final int httpMaxConnections =
78 httpKeepAlive ? Integer.parseInt(System.getProperty("http.maxConnections", "5")) : 0;
79 private static final long httpKeepAliveDurationMs =
80 Long.parseLong(System.getProperty("http.keepAliveDuration", "300000")); // 5 minutes.
81
Robert Greenwalt85956262014-05-18 20:29:39 -070082 /**
83 * @hide
84 */
Robert Greenwalt9ba9c582014-03-19 17:56:12 -070085 public Network(int netId) {
86 this.netId = netId;
87 }
88
Robert Greenwalt85956262014-05-18 20:29:39 -070089 /**
90 * @hide
91 */
Robert Greenwalt9ba9c582014-03-19 17:56:12 -070092 public Network(Network that) {
93 this.netId = that.netId;
94 }
95
Paul Jensen3e32a4b2014-05-13 19:05:13 -040096 /**
97 * Operates the same as {@code InetAddress.getAllByName} except that host
98 * resolution is done on this network.
99 *
100 * @param host the hostname or literal IP string to be resolved.
101 * @return the array of addresses associated with the specified host.
102 * @throws UnknownHostException if the address lookup fails.
103 */
104 public InetAddress[] getAllByName(String host) throws UnknownHostException {
105 return InetAddress.getAllByNameOnNet(host, netId);
106 }
107
108 /**
109 * Operates the same as {@code InetAddress.getByName} except that host
110 * resolution is done on this network.
111 *
112 * @param host
113 * the hostName to be resolved to an address or {@code null}.
114 * @return the {@code InetAddress} instance representing the host.
115 * @throws UnknownHostException
116 * if the address lookup fails.
117 */
118 public InetAddress getByName(String host) throws UnknownHostException {
119 return InetAddress.getByNameOnNet(host, netId);
120 }
121
Robert Greenwalt85956262014-05-18 20:29:39 -0700122 /**
Paul Jensen2d6f2652014-05-20 11:25:35 -0400123 * A {@code SocketFactory} that produces {@code Socket}'s bound to this network.
124 */
125 private class NetworkBoundSocketFactory extends SocketFactory {
126 private final int mNetId;
127
128 public NetworkBoundSocketFactory(int netId) {
129 super();
130 mNetId = netId;
131 }
132
Lorenzo Colittif0382892014-07-30 17:17:13 +0900133 private Socket connectToHost(String host, int port, SocketAddress localAddress)
134 throws IOException {
Paul Jensen8ef34012014-05-27 10:19:39 -0400135 // Lookup addresses only on this Network.
136 InetAddress[] hostAddresses = getAllByName(host);
Lorenzo Colittif0382892014-07-30 17:17:13 +0900137 // Try all addresses.
138 for (int i = 0; i < hostAddresses.length; i++) {
Paul Jensen8ef34012014-05-27 10:19:39 -0400139 try {
Lorenzo Colittif0382892014-07-30 17:17:13 +0900140 Socket socket = createSocket();
141 if (localAddress != null) socket.bind(localAddress);
Paul Jensen8ef34012014-05-27 10:19:39 -0400142 socket.connect(new InetSocketAddress(hostAddresses[i], port));
Lorenzo Colittif0382892014-07-30 17:17:13 +0900143 return socket;
Paul Jensen8ef34012014-05-27 10:19:39 -0400144 } catch (IOException e) {
Lorenzo Colittif0382892014-07-30 17:17:13 +0900145 if (i == (hostAddresses.length - 1)) throw e;
Paul Jensen8ef34012014-05-27 10:19:39 -0400146 }
147 }
Lorenzo Colittif0382892014-07-30 17:17:13 +0900148 throw new UnknownHostException(host);
Paul Jensen8ef34012014-05-27 10:19:39 -0400149 }
150
Paul Jensen2d6f2652014-05-20 11:25:35 -0400151 @Override
152 public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException {
Lorenzo Colittif0382892014-07-30 17:17:13 +0900153 return connectToHost(host, port, new InetSocketAddress(localHost, localPort));
Paul Jensen2d6f2652014-05-20 11:25:35 -0400154 }
155
156 @Override
157 public Socket createSocket(InetAddress address, int port, InetAddress localAddress,
158 int localPort) throws IOException {
159 Socket socket = createSocket();
160 socket.bind(new InetSocketAddress(localAddress, localPort));
161 socket.connect(new InetSocketAddress(address, port));
162 return socket;
163 }
164
165 @Override
166 public Socket createSocket(InetAddress host, int port) throws IOException {
167 Socket socket = createSocket();
168 socket.connect(new InetSocketAddress(host, port));
169 return socket;
170 }
171
172 @Override
173 public Socket createSocket(String host, int port) throws IOException {
Lorenzo Colittif0382892014-07-30 17:17:13 +0900174 return connectToHost(host, port, null);
Paul Jensen2d6f2652014-05-20 11:25:35 -0400175 }
176
177 @Override
178 public Socket createSocket() throws IOException {
179 Socket socket = new Socket();
Lorenzo Colitti9f1274b2014-08-21 11:45:54 -0700180 bindSocket(socket);
Paul Jensen2d6f2652014-05-20 11:25:35 -0400181 return socket;
182 }
183 }
184
185 /**
Robert Greenwalt85956262014-05-18 20:29:39 -0700186 * Returns a {@link SocketFactory} bound to this network. Any {@link Socket} created by
187 * this factory will have its traffic sent over this {@code Network}. Note that if this
188 * {@code Network} ever disconnects, this factory and any {@link Socket} it produced in the
189 * past or future will cease to work.
190 *
191 * @return a {@link SocketFactory} which produces {@link Socket} instances bound to this
192 * {@code Network}.
193 */
Paul Jensen0a363a32014-05-29 10:12:39 -0400194 public SocketFactory getSocketFactory() {
Lorenzo Colitti5b37fa22014-07-29 22:51:27 +0900195 if (mNetworkBoundSocketFactory == null) {
196 synchronized (mLock) {
197 if (mNetworkBoundSocketFactory == null) {
198 mNetworkBoundSocketFactory = new NetworkBoundSocketFactory(netId);
199 }
Lorenzo Colittic473dc42014-07-18 01:34:19 +0900200 }
Paul Jensen2d6f2652014-05-20 11:25:35 -0400201 }
202 return mNetworkBoundSocketFactory;
Robert Greenwalt85956262014-05-18 20:29:39 -0700203 }
204
Paul Jensen07ed0742014-09-08 14:59:09 -0400205 // TODO: This creates a connection pool and host resolver for
Lorenzo Colitti0ed0a282014-08-28 17:15:40 -0700206 // every Network object, instead of one for every NetId. This is
207 // suboptimal, because an app could potentially have more than one
208 // Network object for the same NetId, causing increased memory footprint
209 // and performance penalties due to lack of connection reuse (connection
210 // setup time, congestion window growth time, etc.).
211 //
Paul Jensen07ed0742014-09-08 14:59:09 -0400212 // Instead, investigate only having one connection pool and host resolver
213 // for every NetId, perhaps by using a static HashMap of NetIds to
214 // connection pools and host resolvers. The tricky part is deciding when
215 // to remove a map entry; a WeakHashMap shouldn't be used because whether
216 // a Network is referenced doesn't correlate with whether a new Network
217 // will be instantiated in the near future with the same NetID. A good
218 // solution would involve purging empty (or when all connections are timed
219 // out) ConnectionPools.
Lorenzo Colitti9f1274b2014-08-21 11:45:54 -0700220 private void maybeInitHttpClient() {
Paul Jensen07ed0742014-09-08 14:59:09 -0400221 synchronized (mLock) {
Neil Fuller50a01d82015-01-12 16:49:06 +0000222 if (mNetwork == null) {
223 mNetwork = new com.android.okhttp.internal.Network() {
Paul Jensen07ed0742014-09-08 14:59:09 -0400224 @Override
Neil Fuller50a01d82015-01-12 16:49:06 +0000225 public InetAddress[] resolveInetAddresses(String host) throws UnknownHostException {
Paul Jensen07ed0742014-09-08 14:59:09 -0400226 return Network.this.getAllByName(host);
227 }
228 };
229 }
230 if (mConnectionPool == null) {
231 mConnectionPool = new ConnectionPool(httpMaxConnections,
232 httpKeepAliveDurationMs);
Lorenzo Colitti5b37fa22014-07-29 22:51:27 +0900233 }
Lorenzo Colitti5b37fa22014-07-29 22:51:27 +0900234 }
Lorenzo Colitti5b37fa22014-07-29 22:51:27 +0900235 }
236
237 /**
Lorenzo Colitti9f1274b2014-08-21 11:45:54 -0700238 * Opens the specified {@link URL} on this {@code Network}, such that all traffic will be sent
239 * on this Network. The URL protocol must be {@code HTTP} or {@code HTTPS}.
240 *
241 * @return a {@code URLConnection} to the resource referred to by this URL.
242 * @throws MalformedURLException if the URL protocol is not HTTP or HTTPS.
243 * @throws IOException if an error occurs while opening the connection.
244 * @see java.net.URL#openConnection()
Lorenzo Colitti5b37fa22014-07-29 22:51:27 +0900245 */
Lorenzo Colitti9f1274b2014-08-21 11:45:54 -0700246 public URLConnection openConnection(URL url) throws IOException {
Paul Jensen72db88e2015-03-10 10:54:12 -0400247 final ConnectivityManager cm = ConnectivityManager.getInstanceOrNull();
248 if (cm == null) {
249 throw new IOException("No ConnectivityManager yet constructed, please construct one");
250 }
Paul Jensene0bef712014-12-10 15:12:18 -0500251 // TODO: Should this be optimized to avoid fetching the global proxy for every request?
Paul Jensencee9b512015-05-06 07:32:40 -0400252 final ProxyInfo proxyInfo = cm.getProxyForNetwork(this);
Paul Jensene0bef712014-12-10 15:12:18 -0500253 java.net.Proxy proxy = null;
254 if (proxyInfo != null) {
255 proxy = proxyInfo.makeProxy();
256 } else {
257 proxy = java.net.Proxy.NO_PROXY;
258 }
259 return openConnection(url, proxy);
260 }
261
262 /**
263 * Opens the specified {@link URL} on this {@code Network}, such that all traffic will be sent
264 * on this Network. The URL protocol must be {@code HTTP} or {@code HTTPS}.
265 *
266 * @param proxy the proxy through which the connection will be established.
267 * @return a {@code URLConnection} to the resource referred to by this URL.
268 * @throws MalformedURLException if the URL protocol is not HTTP or HTTPS.
269 * @throws IllegalArgumentException if the argument proxy is null.
270 * @throws IOException if an error occurs while opening the connection.
271 * @see java.net.URL#openConnection()
Paul Jensene0bef712014-12-10 15:12:18 -0500272 */
273 public URLConnection openConnection(URL url, java.net.Proxy proxy) throws IOException {
274 if (proxy == null) throw new IllegalArgumentException("proxy is null");
Lorenzo Colitti9f1274b2014-08-21 11:45:54 -0700275 maybeInitHttpClient();
276 String protocol = url.getProtocol();
Neil Fuller50a01d82015-01-12 16:49:06 +0000277 OkUrlFactory okUrlFactory;
278 // TODO: HttpHandler creates OkUrlFactory instances that share the default ResponseCache.
Paul Jensen07ed0742014-09-08 14:59:09 -0400279 // Could this cause unexpected behavior?
Paul Jensen07ed0742014-09-08 14:59:09 -0400280 if (protocol.equals("http")) {
Neil Fuller7014da72015-01-20 13:21:58 +0000281 okUrlFactory = HttpHandler.createHttpOkUrlFactory(proxy);
Paul Jensen07ed0742014-09-08 14:59:09 -0400282 } else if (protocol.equals("https")) {
Neil Fuller7014da72015-01-20 13:21:58 +0000283 okUrlFactory = HttpsHandler.createHttpsOkUrlFactory(proxy);
Paul Jensen07ed0742014-09-08 14:59:09 -0400284 } else {
Neil Fuller50a01d82015-01-12 16:49:06 +0000285 // OkHttp only supports HTTP and HTTPS and returns a null URLStreamHandler if
Lorenzo Colitti9f1274b2014-08-21 11:45:54 -0700286 // passed another protocol.
287 throw new MalformedURLException("Invalid URL or unrecognized protocol " + protocol);
Lorenzo Colittic473dc42014-07-18 01:34:19 +0900288 }
Neil Fuller50a01d82015-01-12 16:49:06 +0000289 OkHttpClient client = okUrlFactory.client();
290 client.setSocketFactory(getSocketFactory()).setConnectionPool(mConnectionPool);
291
292 // Use internal APIs to change the Network.
293 Internal.instance.setNetwork(client, mNetwork);
294
295 return okUrlFactory.open(url);
Lorenzo Colitti9f1274b2014-08-21 11:45:54 -0700296 }
297
298 /**
Sreeram Ramachandrane15db7c2014-10-22 11:10:20 -0700299 * Binds the specified {@link DatagramSocket} to this {@code Network}. All data traffic on the
300 * socket will be sent on this {@code Network}, irrespective of any process-wide network binding
Paul Jensen72db88e2015-03-10 10:54:12 -0400301 * set by {@link ConnectivityManager#bindProcessToNetwork}. The socket must not be
Sreeram Ramachandrane15db7c2014-10-22 11:10:20 -0700302 * connected.
303 */
304 public void bindSocket(DatagramSocket socket) throws IOException {
Sreeram Ramachandrane15db7c2014-10-22 11:10:20 -0700305 // Query a property of the underlying socket to ensure that the socket's file descriptor
306 // exists, is available to bind to a network and is not closed.
307 socket.getReuseAddress();
Erik Klined8959992015-06-05 17:37:45 +0900308 bindSocket(socket.getFileDescriptor$());
Sreeram Ramachandrane15db7c2014-10-22 11:10:20 -0700309 }
310
311 /**
Lorenzo Colitti9f1274b2014-08-21 11:45:54 -0700312 * Binds the specified {@link Socket} to this {@code Network}. All data traffic on the socket
313 * will be sent on this {@code Network}, irrespective of any process-wide network binding set by
Paul Jensen72db88e2015-03-10 10:54:12 -0400314 * {@link ConnectivityManager#bindProcessToNetwork}. The socket must not be connected.
Lorenzo Colitti9f1274b2014-08-21 11:45:54 -0700315 */
316 public void bindSocket(Socket socket) throws IOException {
Sreeram Ramachandrane15db7c2014-10-22 11:10:20 -0700317 // Query a property of the underlying socket to ensure that the socket's file descriptor
318 // exists, is available to bind to a network and is not closed.
Lorenzo Colitti9f1274b2014-08-21 11:45:54 -0700319 socket.getReuseAddress();
Erik Klined8959992015-06-05 17:37:45 +0900320 bindSocket(socket.getFileDescriptor$());
Sreeram Ramachandrane15db7c2014-10-22 11:10:20 -0700321 }
322
Erik Klined8959992015-06-05 17:37:45 +0900323 /**
324 * Binds the specified {@link FileDescriptor} to this {@code Network}. All data traffic on the
325 * socket represented by this file descriptor will be sent on this {@code Network},
326 * irrespective of any process-wide network binding set by
327 * {@link ConnectivityManager#bindProcessToNetwork}. The socket must not be connected.
328 */
329 public void bindSocket(FileDescriptor fd) throws IOException {
330 try {
331 final SocketAddress peer = Os.getpeername(fd);
332 final InetAddress inetPeer = ((InetSocketAddress) peer).getAddress();
333 if (!inetPeer.isAnyLocalAddress()) {
334 // Apparently, the kernel doesn't update a connected UDP socket's
335 // routing upon mark changes.
336 throw new SocketException("Socket is connected");
337 }
338 } catch (ErrnoException e) {
339 // getpeername() failed.
340 if (e.errno != OsConstants.ENOTCONN) {
341 throw e.rethrowAsSocketException();
342 }
343 } catch (ClassCastException e) {
344 // Wasn't an InetSocketAddress.
345 throw new SocketException("Only AF_INET/AF_INET6 sockets supported");
346 }
347
348 final int err = NetworkUtils.bindSocketToNetwork(fd.getInt$(), netId);
Lorenzo Colitti9f1274b2014-08-21 11:45:54 -0700349 if (err != 0) {
350 // bindSocketToNetwork returns negative errno.
351 throw new ErrnoException("Binding socket to network " + netId, -err)
352 .rethrowAsSocketException();
353 }
Lorenzo Colittic473dc42014-07-18 01:34:19 +0900354 }
355
Erik Kline25f3b7b2015-03-05 15:13:37 +0900356 /**
357 * Returns a handle representing this {@code Network}, for use with the NDK API.
358 */
359 public long getNetworkHandle() {
360 // The network handle is explicitly not the same as the netId.
361 //
362 // The netId is an implementation detail which might be changed in the
363 // future, or which alone (i.e. in the absence of some additional
364 // context) might not be sufficient to fully identify a Network.
365 //
366 // As such, the intention is to prevent accidental misuse of the API
367 // that might result if a developer assumed that handles and netIds
368 // were identical and passing a netId to a call expecting a handle
369 // "just worked". Such accidental misuse, if widely deployed, might
370 // prevent future changes to the semantics of the netId field or
371 // inhibit the expansion of state required for Network objects.
372 //
373 // This extra layer of indirection might be seen as paranoia, and might
374 // never end up being necessary, but the added complexity is trivial.
375 // At some future date it may be desirable to realign the handle with
376 // Multiple Provisioning Domains API recommendations, as made by the
377 // IETF mif working group.
378 //
379 // The HANDLE_MAGIC value MUST be kept in sync with the corresponding
380 // value in the native/android/net.c NDK implementation.
Erik Klinee1a6cf22015-05-14 15:40:07 +0900381 if (netId == 0) {
382 return 0L; // make this zero condition obvious for debugging
383 }
Erik Kline25f3b7b2015-03-05 15:13:37 +0900384 final long HANDLE_MAGIC = 0xfacade;
385 return (((long) netId) << 32) | HANDLE_MAGIC;
386 }
387
Robert Greenwalt9ba9c582014-03-19 17:56:12 -0700388 // implement the Parcelable interface
389 public int describeContents() {
390 return 0;
391 }
392 public void writeToParcel(Parcel dest, int flags) {
393 dest.writeInt(netId);
394 }
395
396 public static final Creator<Network> CREATOR =
397 new Creator<Network>() {
398 public Network createFromParcel(Parcel in) {
399 int netId = in.readInt();
400
401 return new Network(netId);
402 }
403
404 public Network[] newArray(int size) {
405 return new Network[size];
406 }
407 };
Robert Greenwalt85956262014-05-18 20:29:39 -0700408
Robert Greenwalt2c7bf2c2014-06-23 16:07:43 -0700409 @Override
Robert Greenwalt85956262014-05-18 20:29:39 -0700410 public boolean equals(Object obj) {
411 if (obj instanceof Network == false) return false;
412 Network other = (Network)obj;
413 return this.netId == other.netId;
414 }
415
Robert Greenwalt2c7bf2c2014-06-23 16:07:43 -0700416 @Override
Robert Greenwalt85956262014-05-18 20:29:39 -0700417 public int hashCode() {
418 return netId * 11;
419 }
Robert Greenwalt2c7bf2c2014-06-23 16:07:43 -0700420
421 @Override
422 public String toString() {
423 return Integer.toString(netId);
424 }
Robert Greenwalt9ba9c582014-03-19 17:56:12 -0700425}