-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathfreedom-module.ts
55 lines (46 loc) · 1.96 KB
/
freedom-module.ts
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
import * as bridge from '../bridge/bridge';
import * as logging from '../logging/logging';
import * as loggingTypes from '../loggingprovider/loggingprovider.types';
import * as net from '../net/net.types';
import * as rtc_to_net from '../rtc-to-net/rtc-to-net';
import * as socks_to_rtc from '../socks-to-rtc/socks-to-rtc';
import * as tcp from '../net/tcp';
declare const freedom: freedom.FreedomInModuleEnv;
const loggingController = freedom['loggingcontroller']();
loggingController.setDefaultFilter(loggingTypes.Destination.console,
loggingTypes.Level.debug);
const log :logging.Log = new logging.Log('simple-socks');
const socksEndpoint:net.Endpoint = {
address: '0.0.0.0',
port: 9999
};
const pcConfig :freedom.RTCPeerConnection.RTCConfiguration = {
iceServers: [{urls: ['stun:stun.l.google.com:19302']},
{urls: ['stun:stun.services.mozilla.com']}]
};
export const socksToRtc = new socks_to_rtc.SocksToRtc();
export const rtcToNet = new rtc_to_net.RtcToNet();
rtcToNet.start({
allowNonUnicast: true
}, bridge.best('rtctonet', pcConfig)).then(() => {
log.info('RtcToNet ready');
}, (e:Error) => {
log.error('failed to start RtcToNet: %1', e.message);
});
socksToRtc.start(
new tcp.Server(socksEndpoint),
// If you encounter issues w/obfuscation, replace bridge.best(...)
// with bridge.preObfuscation('sockstortc', pcConfig))
bridge.best('sockstortc', pcConfig, undefined, {
// See churn pipe source for the full list of transformer names.
name: 'rc4'
})).then((endpoint:net.Endpoint) => {
log.info('SocksToRtc listening on %1', endpoint);
log.info('curl -x socks5h://%1:%2 www.example.com',
endpoint.address, endpoint.port);
}, (e:Error) => {
log.error('failed to start SocksToRtc: %1', e.message);
});
// Must do this after calling start.
rtcToNet.signalsForPeer.setSyncHandler(socksToRtc.handleSignalFromPeer);
socksToRtc.signalsForPeer.setSyncHandler(rtcToNet.handleSignalFromPeer);