1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { ITunnelEndpoint, parseSocketAddress } from '../../shared/daemon-rpc-types';
import ConnectionPanel, {
IBridgeData,
IInAddress,
IObfuscationData,
IOutAddress,
} from '../components/ConnectionPanel';
import { IReduxState, ReduxDispatch } from '../redux/store';
import userInterfaceActions from '../redux/userinterface/actions';
function tunnelEndpointToRelayInAddress(tunnelEndpoint: ITunnelEndpoint): IInAddress {
const socketAddr = parseSocketAddress(tunnelEndpoint.address);
return {
ip: socketAddr.host,
port: socketAddr.port,
protocol: tunnelEndpoint.protocol,
tunnelType: tunnelEndpoint.tunnelType,
};
}
function tunnelEndpointToEntryLocationInAddress(
tunnelEndpoint: ITunnelEndpoint,
): IInAddress | undefined {
if (!tunnelEndpoint.entryEndpoint) {
return undefined;
}
const socketAddr = parseSocketAddress(tunnelEndpoint.entryEndpoint.address);
return {
ip: socketAddr.host,
port: socketAddr.port,
protocol: tunnelEndpoint.entryEndpoint.transportProtocol,
tunnelType: tunnelEndpoint.tunnelType,
};
}
function tunnelEndpointToBridgeData(endpoint: ITunnelEndpoint): IBridgeData | undefined {
if (!endpoint.proxy) {
return undefined;
}
const socketAddr = parseSocketAddress(endpoint.proxy.address);
return {
ip: socketAddr.host,
port: socketAddr.port,
protocol: endpoint.proxy.protocol,
bridgeType: endpoint.proxy.proxyType,
};
}
function tunnelEndpointToObfuscationEndpoint(
endpoint: ITunnelEndpoint,
): IObfuscationData | undefined {
if (!endpoint.obfuscationEndpoint) {
return undefined;
}
return {
ip: endpoint.obfuscationEndpoint.address,
port: endpoint.obfuscationEndpoint.port,
protocol: endpoint.obfuscationEndpoint.protocol,
obfuscationType: endpoint.obfuscationEndpoint.obfuscationType,
};
}
const mapStateToProps = (state: IReduxState) => {
const status = state.connection.status;
const outAddress: IOutAddress = {
ipv4: state.connection.ipv4,
ipv6: state.connection.ipv6,
};
const inAddress: IInAddress | undefined =
(status.state === 'connecting' || status.state === 'connected') && status.details
? tunnelEndpointToRelayInAddress(status.details.endpoint)
: undefined;
const entryLocationInAddress: IInAddress | undefined =
(status.state === 'connecting' || status.state === 'connected') && status.details
? tunnelEndpointToEntryLocationInAddress(status.details.endpoint)
: undefined;
const bridgeInfo: IBridgeData | undefined =
(status.state === 'connecting' || status.state === 'connected') && status.details
? tunnelEndpointToBridgeData(status.details.endpoint)
: undefined;
const obfuscationEndpoint: IObfuscationData | undefined =
(status.state === 'connecting' || status.state === 'connected') && status.details
? tunnelEndpointToObfuscationEndpoint(status.details.endpoint)
: undefined;
return {
isOpen: state.userInterface.connectionPanelVisible,
hostname: state.connection.hostname,
bridgeHostname: state.connection.bridgeHostname,
entryHostname: state.connection.entryHostname,
inAddress,
entryLocationInAddress,
bridgeInfo,
outAddress,
obfuscationEndpoint,
};
};
const mapDispatchToProps = (dispatch: ReduxDispatch) => {
const userInterface = bindActionCreators(userInterfaceActions, dispatch);
return {
onToggle: userInterface.toggleConnectionPanel,
};
};
export default connect(mapStateToProps, mapDispatchToProps)(ConnectionPanel);
|