Skip to content

Commit a874f56

Browse files
committed
Merge pull request #1732 from uProxy/iislucas-r0.8.14
Pulling in fixes for testing release candidate for r0.8.14
2 parents ca2b562 + a4c92ac commit a874f56

File tree

3 files changed

+65
-98
lines changed

3 files changed

+65
-98
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"lodash": "^3.7.0",
4848
"regex2dfa": "^0.1.6",
4949
"tsd": "^0.5.7",
50-
"uproxy-lib": "^27.2.5",
50+
"uproxy-lib": "^28.0.0",
5151
"utransformers": "^0.2.1",
5252
"xregexp": "^2.0.0"
5353
},

src/generic_core/diagnose-nat.ts

Lines changed: 64 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -613,13 +613,6 @@ export function doUdpTest() {
613613
}
614614

615615
socket.bind('0.0.0.0', 0)
616-
.then((result :number) => {
617-
if (result != 0) {
618-
return Promise.reject(new Error('listen failed to bind :5758' +
619-
' with result code ' + result));
620-
}
621-
return Promise.resolve(result);
622-
})
623616
.then(socket.getInfo)
624617
.then((socketInfo: freedom_UdpSocket.SocketInfo) => {
625618
log.debug('listening on %1:%2',
@@ -694,13 +687,7 @@ function pingStunServer(serverAddr: string) {
694687

695688
var bytes = Turn.formatStunMessage(bindRequest);
696689
socket.bind('0.0.0.0', 0)
697-
.then((result: number) => {
698-
if (result != 0) {
699-
return Promise.reject(new Error('listen failed to bind :5758' +
700-
' with result code ' + result));
701-
}
702-
return Promise.resolve(result);
703-
}).then(() => {
690+
.then(() => {
704691
return socket.sendTo(bytes.buffer, parts[1], parseInt(parts[2]));
705692
}).then((written: number) => {
706693
log.debug('%1 bytes sent correctly', [written]);
@@ -769,12 +756,6 @@ export function doNatProvoking() :Promise<string> {
769756
socket.on('onData', onUdpData);
770757

771758
socket.bind('0.0.0.0', 0)
772-
.then((result: number) => {
773-
if (result != 0) {
774-
return Promise.reject(new Error('failed to bind to a port: err=' + result));
775-
}
776-
return Promise.resolve(result);
777-
})
778759
.then(socket.getInfo)
779760
.then((socketInfo: freedom_UdpSocket.SocketInfo) => {
780761
log.debug('listening on %1:%2',
@@ -880,27 +861,23 @@ export function probePmpSupport(routerIp:string, privateIp:string) :Promise<bool
880861

881862
// Bind a UDP port and send a NAT-PMP request
882863
socket.bind('0.0.0.0', 0).
883-
then((result:number) => {
884-
if (result != 0) {
885-
R(new Error('Failed to bind to a port: Err= ' + result));
886-
}
887-
888-
// Construct the NAT-PMP map request as an ArrayBuffer
889-
// Map internal port 55555 to external port 55555 w/ 120 sec lifetime
890-
var pmpBuffer = new ArrayBuffer(12);
891-
var pmpView = new DataView(pmpBuffer);
892-
// Version and OP fields (1 byte each)
893-
pmpView.setInt8(0, 0);
894-
pmpView.setInt8(1, 1);
895-
// Reserved, internal port, external port fields (2 bytes each)
896-
pmpView.setInt16(2, 0, false);
897-
pmpView.setInt16(4, 55555, false);
898-
pmpView.setInt16(6, 55555, false);
899-
// Mapping lifetime field (4 bytes)
900-
pmpView.setInt32(8, 120, false);
901-
902-
socket.sendTo(pmpBuffer, routerIp, 5351);
903-
});
864+
then(() => {
865+
// Construct the NAT-PMP map request as an ArrayBuffer
866+
// Map internal port 55555 to external port 55555 w/ 120 sec lifetime
867+
var pmpBuffer = new ArrayBuffer(12);
868+
var pmpView = new DataView(pmpBuffer);
869+
// Version and OP fields (1 byte each)
870+
pmpView.setInt8(0, 0);
871+
pmpView.setInt8(1, 1);
872+
// Reserved, internal port, external port fields (2 bytes each)
873+
pmpView.setInt16(2, 0, false);
874+
pmpView.setInt16(4, 55555, false);
875+
pmpView.setInt16(6, 55555, false);
876+
// Mapping lifetime field (4 bytes)
877+
pmpView.setInt32(8, 120, false);
878+
879+
socket.sendTo(pmpBuffer, routerIp, 5351);
880+
}).catch(R);
904881
});
905882

906883
// Give _probePmpSupport 2 seconds before timing out
@@ -924,54 +901,50 @@ export function probePcpSupport(routerIp:string, privateIp:string) :Promise<bool
924901

925902
// Bind a UDP port and send a PCP request
926903
socket.bind('0.0.0.0', 0).
927-
then((result:number) => {
928-
if (result != 0) {
929-
R(new Error('Failed to bind to a port: Err= ' + result));
930-
}
931-
932-
// Create the PCP MAP request as an ArrayBuffer
933-
// Map internal port 55556 to external port 55556 w/ 120 sec lifetime
934-
var pcpBuffer = new ArrayBuffer(60);
935-
var pcpView = new DataView(pcpBuffer);
936-
// Version field (1 byte)
937-
pcpView.setInt8(0, 0b00000010);
938-
// R and Opcode fields (1 bit + 7 bits)
939-
pcpView.setInt8(1, 0b00000001);
940-
// Reserved field (2 bytes)
941-
pcpView.setInt16(2, 0, false);
942-
// Requested lifetime (4 bytes)
943-
pcpView.setInt32(4, 120, false);
944-
// Client IP address (128 bytes; we use the IPv4 -> IPv6 mapping)
945-
pcpView.setInt32(8, 0, false);
946-
pcpView.setInt32(12, 0, false);
947-
pcpView.setInt16(16, 0, false);
948-
pcpView.setInt16(18, 0xffff, false);
949-
// Start of IPv4 octets of the client's private IP
950-
var ipOctets = ipaddr.IPv4.parse(privateIp).octets;
951-
pcpView.setInt8(20, ipOctets[0]);
952-
pcpView.setInt8(21, ipOctets[1]);
953-
pcpView.setInt8(22, ipOctets[2]);
954-
pcpView.setInt8(23, ipOctets[3]);
955-
// Mapping Nonce (12 bytes)
956-
pcpView.setInt32(24, randInt(0, 0xffffffff), false);
957-
pcpView.setInt32(28, randInt(0, 0xffffffff), false);
958-
pcpView.setInt32(32, randInt(0, 0xffffffff), false);
959-
// Protocol (1 byte)
960-
pcpView.setInt8(36, 17);
961-
// Reserved (3 bytes)
962-
pcpView.setInt16(37, 0, false);
963-
pcpView.setInt8(39, 0);
964-
// Internal and external ports
965-
pcpView.setInt16(40, 55556, false);
966-
pcpView.setInt16(42, 55556, false);
967-
// External IP address (128 bytes; we use the all-zero IPv4 -> IPv6 mapping)
968-
pcpView.setFloat64(44, 0, false);
969-
pcpView.setInt16(52, 0, false);
970-
pcpView.setInt16(54, 0xffff, false);
971-
pcpView.setInt32(56, 0, false);
972-
973-
socket.sendTo(pcpBuffer, routerIp, 5351);
974-
});
904+
then(() => {
905+
// Create the PCP MAP request as an ArrayBuffer
906+
// Map internal port 55556 to external port 55556 w/ 120 sec lifetime
907+
var pcpBuffer = new ArrayBuffer(60);
908+
var pcpView = new DataView(pcpBuffer);
909+
// Version field (1 byte)
910+
pcpView.setInt8(0, 0b00000010);
911+
// R and Opcode fields (1 bit + 7 bits)
912+
pcpView.setInt8(1, 0b00000001);
913+
// Reserved field (2 bytes)
914+
pcpView.setInt16(2, 0, false);
915+
// Requested lifetime (4 bytes)
916+
pcpView.setInt32(4, 120, false);
917+
// Client IP address (128 bytes; we use the IPv4 -> IPv6 mapping)
918+
pcpView.setInt32(8, 0, false);
919+
pcpView.setInt32(12, 0, false);
920+
pcpView.setInt16(16, 0, false);
921+
pcpView.setInt16(18, 0xffff, false);
922+
// Start of IPv4 octets of the client's private IP
923+
var ipOctets = ipaddr.IPv4.parse(privateIp).octets;
924+
pcpView.setInt8(20, ipOctets[0]);
925+
pcpView.setInt8(21, ipOctets[1]);
926+
pcpView.setInt8(22, ipOctets[2]);
927+
pcpView.setInt8(23, ipOctets[3]);
928+
// Mapping Nonce (12 bytes)
929+
pcpView.setInt32(24, randInt(0, 0xffffffff), false);
930+
pcpView.setInt32(28, randInt(0, 0xffffffff), false);
931+
pcpView.setInt32(32, randInt(0, 0xffffffff), false);
932+
// Protocol (1 byte)
933+
pcpView.setInt8(36, 17);
934+
// Reserved (3 bytes)
935+
pcpView.setInt16(37, 0, false);
936+
pcpView.setInt8(39, 0);
937+
// Internal and external ports
938+
pcpView.setInt16(40, 55556, false);
939+
pcpView.setInt16(42, 55556, false);
940+
// External IP address (128 bytes; we use the all-zero IPv4 -> IPv6 mapping)
941+
pcpView.setFloat64(44, 0, false);
942+
pcpView.setInt16(52, 0, false);
943+
pcpView.setInt16(54, 0xffff, false);
944+
pcpView.setInt32(56, 0, false);
945+
946+
socket.sendTo(pcpBuffer, routerIp, 5351);
947+
}).catch(R);
975948
});
976949

977950
// Give _probePcpSupport 2 seconds before timing out
@@ -1008,11 +981,7 @@ function sendSsdpRequest(privateIp:string) :Promise<ArrayBuffer> {
1008981

1009982
// Bind a socket and send the SSDP request
1010983
socket.bind('0.0.0.0', 0).
1011-
then((result:number) => {
1012-
if (result != 0) {
1013-
R(new Error('Failed to bind to a port: Err= ' + result));
1014-
}
1015-
984+
then(() => {
1016985
// Construct and send a UPnP SSDP message
1017986
var ssdpStr = 'M-SEARCH * HTTP/1.1\r\n' +
1018987
'HOST: 239.255.255.250:1900\r\n' +
@@ -1021,7 +990,7 @@ function sendSsdpRequest(privateIp:string) :Promise<ArrayBuffer> {
1021990
'ST: urn:schemas-upnp-org:device:InternetGatewayDevice:1';
1022991
var ssdpBuffer = arraybuffers.stringToArrayBuffer(ssdpStr);
1023992
socket.sendTo(ssdpBuffer, '239.255.255.250', 1900);
1024-
});
993+
}).catch(R);
1025994
});
1026995

1027996
// Give _sendSsdpRequest 1 second before timing out

src/mocks/rtc-to-net.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,4 @@ export class RtcToNetMock { // TODO implements rtc_to_net.RtcToNet {
3434

3535
public toString = () => {
3636
}
37-
38-
public startFromConfig = () => {}
3937
}

0 commit comments

Comments
 (0)