Skip to content

Commit

Permalink
Update gRPC client in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
dlon committed Sep 25, 2023
1 parent a02a6e4 commit c780677
Showing 1 changed file with 36 additions and 40 deletions.
76 changes: 36 additions & 40 deletions gui/src/main/daemon-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,11 @@ export class DaemonRpc {

if (settingsUpdate.tunnelProtocol) {
const tunnelTypeUpdate = new grpcTypes.TunnelTypeUpdate();
tunnelTypeUpdate.setTunnelType(
convertToTunnelTypeConstraint(settingsUpdate.tunnelProtocol),
);
if (settingsUpdate.tunnelProtocol !== 'any') {
tunnelTypeUpdate.setTunnelType(

Check failure on line 306 in gui/src/main/daemon-rpc.ts

View workflow job for this annotation

GitHub Actions / check-frontend (ubuntu-latest)

Replace `⏎············convertToTunnelType(settingsUpdate.tunnelProtocol.only),⏎··········` with `convertToTunnelType(settingsUpdate.tunnelProtocol.only)`
convertToTunnelType(settingsUpdate.tunnelProtocol.only),
);
}
normalUpdate.setTunnelType(tunnelTypeUpdate);
}

Expand Down Expand Up @@ -412,11 +414,11 @@ export class DaemonRpc {

if (obfuscationSettings.udp2tcpSettings) {
const grpcUdp2tcpSettings = new grpcTypes.Udp2TcpObfuscationSettings();
grpcUdp2tcpSettings.setPort(
obfuscationSettings.udp2tcpSettings.port === 'any'
? 0
: obfuscationSettings.udp2tcpSettings.port.only,
);
if (obfuscationSettings.udp2tcpSettings.port !== 'any') {
grpcUdp2tcpSettings.setPort(

Check failure on line 418 in gui/src/main/daemon-rpc.ts

View workflow job for this annotation

GitHub Actions / check-frontend (ubuntu-latest)

Replace `⏎··········obfuscationSettings.udp2tcpSettings.port.only,⏎········` with `obfuscationSettings.udp2tcpSettings.port.only`
obfuscationSettings.udp2tcpSettings.port.only,
);
}
grpcObfuscationSettings.setUdp2tcp(grpcUdp2tcpSettings);
}

Expand Down Expand Up @@ -957,7 +959,7 @@ function convertFromBlockingError(
return { type: FirewallPolicyErrorType.generic };
case grpcTypes.ErrorState.FirewallPolicyError.ErrorType.LOCKED: {
const pid = error.lockPid;
const name = error.lockName;
const name = error.lockName!;
return { type: FirewallPolicyErrorType.locked, pid, name };
}
}
Expand Down Expand Up @@ -1113,7 +1115,8 @@ function convertFromRelaySettings(
const location = grpcLocation
? { only: convertFromLocation(grpcLocation.toObject()) }
: 'any';
const tunnelProtocol = convertFromTunnelTypeConstraint(normal.getTunnelType()!);
// `getTunnelType()` is not falsy if type is 'any'
const tunnelProtocol = convertFromTunnelTypeConstraint(normal.hasTunnelType() ? normal.getTunnelType() : undefined);

Check failure on line 1119 in gui/src/main/daemon-rpc.ts

View workflow job for this annotation

GitHub Actions / check-frontend (ubuntu-latest)

Replace `normal.hasTunnelType()·?·normal.getTunnelType()·:·undefined` with `⏎··········normal.hasTunnelType()·?·normal.getTunnelType()·:·undefined,⏎········`
const providers = normal.getProvidersList();
const ownership = convertFromOwnership(normal.getOwnership());
const openvpnConstraints = convertFromOpenVpnConstraints(normal.getOpenvpnConstraints()!);
Expand Down Expand Up @@ -1308,8 +1311,8 @@ function convertFromObfuscationSettings(
return {
selectedObfuscation: selectedObfuscationType,
udp2tcpSettings:

Check failure on line 1313 in gui/src/main/daemon-rpc.ts

View workflow job for this annotation

GitHub Actions / check-frontend (ubuntu-latest)

Delete `⏎·····`
obfuscationSettings?.udp2tcp && obfuscationSettings.udp2tcp.port !== 0
? { port: { only: obfuscationSettings.udp2tcp.port } }
obfuscationSettings?.udp2tcp
? { port: convertFromConstraint(obfuscationSettings.udp2tcp.port) }

Check failure on line 1315 in gui/src/main/daemon-rpc.ts

View workflow job for this annotation

GitHub Actions / check-frontend (ubuntu-latest)

Delete `··`
: { port: 'any' },

Check failure on line 1316 in gui/src/main/daemon-rpc.ts

View workflow job for this annotation

GitHub Actions / check-frontend (ubuntu-latest)

Delete `··`
};
}
Expand Down Expand Up @@ -1409,14 +1412,16 @@ function convertFromWireguardConstraints(
result.port = { only: port };
}

const ipVersion = constraints.getIpVersion()?.getProtocol();
switch (ipVersion) {
case grpcTypes.IpVersion.V4:
result.ipVersion = { only: 'ipv4' };
break;
case grpcTypes.IpVersion.V6:
result.ipVersion = { only: 'ipv6' };
break;
// `getIpVersion()` is not falsy if type is 'any'
if (constraints.hasIpVersion()) {
switch (constraints.getIpVersion()) {
case grpcTypes.IpVersion.V4:
result.ipVersion = { only: 'ipv4' };
break;
case grpcTypes.IpVersion.V6:
result.ipVersion = { only: 'ipv6' };
break;
}
}

const entryLocation = constraints.getEntryLocation();
Expand All @@ -1428,9 +1433,9 @@ function convertFromWireguardConstraints(
}

function convertFromTunnelTypeConstraint(
constraint: grpcTypes.TunnelTypeConstraint | undefined,
constraint: grpcTypes.TunnelType | undefined,
): Constraint<TunnelProtocol> {
switch (constraint?.getTunnelType()) {
switch (constraint) {
case grpcTypes.TunnelType.WIREGUARD: {
return { only: 'wireguard' };
}
Expand Down Expand Up @@ -1483,22 +1488,15 @@ function convertToLocation(
return locationConstraint;
}

function convertToTunnelTypeConstraint(
constraint: Constraint<TunnelType>,
): grpcTypes.TunnelTypeConstraint | undefined {
const grpcConstraint = new grpcTypes.TunnelTypeConstraint();

if (constraint !== undefined && constraint !== 'any' && 'only' in constraint) {
switch (constraint.only) {
case 'wireguard':
grpcConstraint.setTunnelType(grpcTypes.TunnelType.WIREGUARD);
return grpcConstraint;
case 'openvpn':
grpcConstraint.setTunnelType(grpcTypes.TunnelType.OPENVPN);
return grpcConstraint;
}
function convertToTunnelType(

Check failure on line 1491 in gui/src/main/daemon-rpc.ts

View workflow job for this annotation

GitHub Actions / check-frontend (ubuntu-latest)

Replace `⏎··tunnelProtocol:·TunnelProtocol,⏎` with `tunnelProtocol:·TunnelProtocol`
tunnelProtocol: TunnelProtocol,
): grpcTypes.TunnelType {
switch (tunnelProtocol) {
case 'wireguard':
return grpcTypes.TunnelType.WIREGUARD;
case 'openvpn':
return grpcTypes.TunnelType.OPENVPN;
}
return undefined;
}

function convertToOpenVpnConstraints(
Expand Down Expand Up @@ -1537,9 +1535,7 @@ function convertToWireguardConstraints(
if (ipVersion) {
const ipVersionProtocol =
ipVersion === 'ipv4' ? grpcTypes.IpVersion.V4 : grpcTypes.IpVersion.V6;
const ipVersionConstraints = new grpcTypes.IpVersionConstraint();
ipVersionConstraints.setProtocol(ipVersionProtocol);
wireguardConstraints.setIpVersion(ipVersionConstraints);
wireguardConstraints.setIpVersion(ipVersionProtocol);
}

if (constraint.useMultihop) {
Expand Down

0 comments on commit c780677

Please sign in to comment.