Skip to content

Commit

Permalink
format code with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomendezroyo committed Sep 2, 2024
1 parent 643e87c commit b2c1122
Showing 1 changed file with 32 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import "./network.scss";
import { InstalledPackageData, PortMapping, PortProtocol } from "@dappnode/types";

const maxRegisteredPortNumber = 32768 - 1;
const maxRegisteredPortNumberPlusOne = maxRegisteredPortNumber + 1;
const maxPortNumber = 65535;
// Wireguard port is inside ephemeral range
const wireguardPort = 51820;
Expand Down Expand Up @@ -129,10 +130,9 @@ export function PortsByService({
}

function getPortStatusSummary(): PortStatusSummary {

const isInEphemeralRange = (port: number) =>
port > maxRegisteredPortNumber && port <= maxPortNumber && port !== wireguardPort;

const isOverTheMax = (port: number) => port > maxPortNumber;

return ports.reduce<PortStatusSummary>(
Expand All @@ -143,7 +143,6 @@ export function PortsByService({

if (isOverTheMax(container)) {
acc.container.overTheMax.push(portMapping);

} else if (isInEphemeralRange(container)) {
acc.container.inEphemeralRange.push(portMapping);
}
Expand All @@ -152,7 +151,6 @@ export function PortsByService({

if (isOverTheMax(host)) {
acc.host.overTheMax.push(portMapping);

} else if (isInEphemeralRange(host)) {
acc.host.inEphemeralRange.push(portMapping);
}
Expand Down Expand Up @@ -198,38 +196,46 @@ export function PortsByService({
for (const conflictingPort of conflictingPorts) {
const portName = `${conflictingPort.host}/${conflictingPort.protocol}`;
const ownerName = prettyDnpName(conflictingPort.owner);
errors.push(
`❌ Port ${portName} is already mapped by the DAppNode Package ${ownerName}`
);
errors.push(`❌ Port ${portName} is already mapped by the DAppNode Package ${ownerName}`);
}

// Adjusting the loops for error and warning outputs accordingly
portStatusSummary.container.overTheMax.forEach(port => {
errors.push(`❌ Container port mapping ${port.container}/${port.protocol} exceeds the maximum allowed port number of ${maxPortNumber} and can't be used.`);
portStatusSummary.container.overTheMax.forEach((port) => {
errors.push(
`❌ Container port mapping ${port.container}/${port.protocol} exceeds the maximum allowed port number of ${maxPortNumber} and can't be used.`
);
});

portStatusSummary.host.overTheMax.forEach(port => {
errors.push(`❌ Host port mapping ${port.host}/${port.protocol} exceeds the maximum allowed port number of ${maxPortNumber} and can't be used.`);
portStatusSummary.host.overTheMax.forEach((port) => {
errors.push(
`❌ Host port mapping ${port.host}/${port.protocol} exceeds the maximum allowed port number of ${maxPortNumber} and can't be used.`
);
});

portStatusSummary.container.inEphemeralRange.forEach(port => {
warnings.push(`⚠️ Package Port mapping ${port.container}/${port.protocol} is in the ephemeral port range (${maxRegisteredPortNumber + 1}-${maxPortNumber}).`);
portStatusSummary.container.inEphemeralRange.forEach((port) => {
warnings.push(
`⚠️ Package Port mapping ${port.container}/${
port.protocol
} is in the ephemeral port range (${maxRegisteredPortNumber + 1}-${maxPortNumber}).`
);
});

portStatusSummary.host.inEphemeralRange.forEach(port => {
warnings.push(`⚠️ Host Port mapping ${port.host}/${port.protocol} is in the ephemeral port range (${maxRegisteredPortNumber + 1}-${maxPortNumber}).`);
portStatusSummary.host.inEphemeralRange.forEach((port) => {
warnings.push(
`⚠️ Host Port mapping ${port.host}/${port.protocol} is in the ephemeral port range (${maxRegisteredPortNumberPlusOne}-${maxPortNumber}).`
);
});

// Aggregate conditions to disable the update
const disableUpdate = Boolean(
areNewMappingsInvalid ||
duplicatedContainerPorts.length > 0 ||
duplicatedHostPorts.length > 0 ||
conflictingPorts.length > 0 ||
arePortsTheSame ||
updating ||
portStatusSummary.container.overTheMax.length > 0 ||
portStatusSummary.host.overTheMax.length > 0
duplicatedContainerPorts.length > 0 ||
duplicatedHostPorts.length > 0 ||
conflictingPorts.length > 0 ||
arePortsTheSame ||
updating ||
portStatusSummary.container.overTheMax.length > 0 ||
portStatusSummary.host.overTheMax.length > 0
);

return (
Expand Down Expand Up @@ -260,11 +266,7 @@ export function PortsByService({
onValueChange={(value: string) => editPort(i, { container: parseInt(value) || undefined })}
/>
) : (
<Input
lock={true}
value={container}
onValueChange={() => { }}
/>
<Input lock={true} value={container} onValueChange={() => {}} />
)}
</td>
<td>
Expand All @@ -279,11 +281,7 @@ export function PortsByService({
}
/>
) : (
<Input
lock={true}
value={protocol}
onValueChange={() => { }}
/>
<Input lock={true} value={protocol} onValueChange={() => {}} />
)}
</td>

Expand All @@ -305,10 +303,8 @@ export function PortsByService({
</div>
))}

{warnings.map(warning => (
<div key={warning}>
{warning}
</div>
{warnings.map((warning) => (
<div key={warning}>{warning}</div>
))}

<div className="button-row">
Expand Down

0 comments on commit b2c1122

Please sign in to comment.