1 module hunt.net.secure.conscrypt.PeerInfoProvider;
2 
3 private __gshared static PeerInfoProvider NULL_PEER_INFO_PROVIDER;
4 
5 shared static this()
6 {
7     NULL_PEER_INFO_PROVIDER = new class PeerInfoProvider {
8         override
9         string getHostname() {
10             return null;
11         }
12 
13         override
14         public string getHostnameOrIP() {
15             return null;
16         }
17 
18         override
19         public int getPort() {
20             return -1;
21         }
22     };
23 }    
24 
25 
26 /**
27  * A provider for the peer host and port information.
28  */
29 abstract class PeerInfoProvider {
30 
31     /**
32      * Returns the hostname supplied during engine/socket creation. No DNS resolution is
33      * attempted before returning the hostname.
34      */
35     abstract string getHostname();
36 
37     /**
38      * This method attempts to create a textual representation of the peer host or IP. Does
39      * not perform a reverse DNS lookup. This is typically used during session creation.
40      */
41     abstract string getHostnameOrIP();
42 
43     /**
44      * Gets the port of the peer.
45      */
46     abstract int getPort();
47 
48     static PeerInfoProvider nullProvider() {
49         return NULL_PEER_INFO_PROVIDER;
50     }
51 
52     static PeerInfoProvider forHostAndPort(string host, int port) {
53         return new class PeerInfoProvider {
54             override
55             string getHostname() {
56                 return host;
57             }
58 
59             override
60             public string getHostnameOrIP() {
61                 return host;
62             }
63 
64             override
65             public int getPort() {
66                 return port;
67             }
68         };
69     }
70 }