View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.http.conn.routing;
29  
30  import java.net.InetAddress;
31  
32  import org.apache.http.HttpHost;
33  
34  /**
35   * Read-only interface for route information.
36   *
37   * @since 4.0
38   */
39  public interface RouteInfo {
40  
41      /**
42       * The tunnelling type of a route.
43       * Plain routes are established by   connecting to the target or
44       * the first proxy.
45       * Tunnelled routes are established by connecting to the first proxy
46       * and tunnelling through all proxies to the target.
47       * Routes without a proxy cannot be tunnelled.
48       */
49      public enum TunnelType { PLAIN, TUNNELLED }
50  
51      /**
52       * The layering type of a route.
53       * Plain routes are established by connecting or tunnelling.
54       * Layered routes are established by layering a protocol such as TLS/SSL
55       * over an existing connection.
56       * Protocols can only be layered over a tunnel to the target, or
57       * or over a direct connection without proxies.
58       * <p>
59       * Layering a protocol
60       * over a direct connection makes little sense, since the connection
61       * could be established with the new protocol in the first place.
62       * But we don't want to exclude that use case.
63       * </p>
64       */
65      public enum LayerType  { PLAIN, LAYERED }
66  
67      /**
68       * Obtains the target host.
69       *
70       * @return the target host
71       */
72      HttpHost getTargetHost();
73  
74      /**
75       * Obtains the local address to connect from.
76       *
77       * @return  the local address,
78       *          or {@code null}
79       */
80      InetAddress getLocalAddress();
81  
82      /**
83       * Obtains the number of hops in this route.
84       * A direct route has one hop. A route through a proxy has two hops.
85       * A route through a chain of <i>n</i> proxies has <i>n+1</i> hops.
86       *
87       * @return  the number of hops in this route
88       */
89      int getHopCount();
90  
91      /**
92       * Obtains the target of a hop in this route.
93       * The target of the last hop is the {@link #getTargetHost target host},
94       * the target of previous hops is the respective proxy in the chain.
95       * For a route through exactly one proxy, target of hop 0 is the proxy
96       * and target of hop 1 is the target host.
97       *
98       * @param hop       index of the hop for which to get the target,
99       *                  0 for first
100      *
101      * @return  the target of the given hop
102      *
103      * @throws IllegalArgumentException
104      *  if the argument is negative or not less than
105      *  {@link #getHopCount getHopCount()}
106      */
107     HttpHost getHopTarget(int hop);
108 
109     /**
110      * Obtains the first proxy host.
111      *
112      * @return the first proxy in the proxy chain, or
113      *         {@code null} if this route is direct
114      */
115     HttpHost getProxyHost();
116 
117     /**
118      * Obtains the tunnel type of this route.
119      * If there is a proxy chain, only end-to-end tunnels are considered.
120      *
121      * @return  the tunnelling type
122      */
123     TunnelType getTunnelType();
124 
125     /**
126      * Checks whether this route is tunnelled through a proxy.
127      * If there is a proxy chain, only end-to-end tunnels are considered.
128      *
129      * @return  {@code true} if tunnelled end-to-end through at least
130      *          one proxy,
131      *          {@code false} otherwise
132      */
133     boolean isTunnelled();
134 
135     /**
136      * Obtains the layering type of this route.
137      * In the presence of proxies, only layering over an end-to-end tunnel
138      * is considered.
139      *
140      * @return  the layering type
141      */
142     LayerType getLayerType();
143 
144     /**
145      * Checks whether this route includes a layered protocol.
146      * In the presence of proxies, only layering over an end-to-end tunnel
147      * is considered.
148      *
149      * @return  {@code true} if layered,
150      *          {@code false} otherwise
151      */
152     boolean isLayered();
153 
154     /**
155      * Checks whether this route is secure.
156      *
157      * @return  {@code true} if secure,
158      *          {@code false} otherwise
159      */
160     boolean isSecure();
161 
162 }