1 /* 2 * Copyright (C) 2020 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 17 package android.net.ipsec.ike; 18 19 import android.annotation.NonNull; 20 import android.net.Network; 21 22 import java.net.InetAddress; 23 import java.util.Objects; 24 25 /** 26 * IkeSessionConnectionInfo represents the connection information of an {@link IkeSession}. 27 * 28 * <p>Connection information includes IP addresses of both the IKE client and server and the network 29 * being used. 30 */ 31 public final class IkeSessionConnectionInfo { 32 private final InetAddress mLocalAddress; 33 private final InetAddress mRemoteAddress; 34 private final Network mNetwork; 35 36 /** 37 * Construct an instance of {@link IkeSessionConnectionInfo}. 38 * 39 * <p>Except for testing, IKE library users normally do not instantiate {@link 40 * IkeSessionConnectionInfo} themselves but instead get a reference via {@link 41 * IkeSessionConfiguration} or {@link IkeSessionCallback} 42 */ IkeSessionConnectionInfo( @onNull InetAddress localAddress, @NonNull InetAddress remoteAddress, @NonNull Network network)43 public IkeSessionConnectionInfo( 44 @NonNull InetAddress localAddress, 45 @NonNull InetAddress remoteAddress, 46 @NonNull Network network) { 47 Objects.requireNonNull(localAddress, "localAddress not provided"); 48 Objects.requireNonNull(remoteAddress, "remoteAddress not provided"); 49 Objects.requireNonNull(network, "network not provided"); 50 51 mLocalAddress = localAddress; 52 mRemoteAddress = remoteAddress; 53 mNetwork = network; 54 } 55 56 /** 57 * Returns the local IP address for the underlying {@link Network} being used. 58 * 59 * @return the local IP address. 60 */ 61 @NonNull getLocalAddress()62 public InetAddress getLocalAddress() { 63 return mLocalAddress; 64 } 65 66 /** 67 * Returns the remote IP address for the underlying {@link Network} being used. 68 * 69 * @return the remote IP address. 70 */ 71 @NonNull getRemoteAddress()72 public InetAddress getRemoteAddress() { 73 return mRemoteAddress; 74 } 75 76 /** 77 * Returns the underlying {@link Network} being used. 78 * 79 * @return the underlying {@link Network} that carries all IKE traffic. 80 */ 81 @NonNull getNetwork()82 public Network getNetwork() { 83 return mNetwork; 84 } 85 } 86