Commit 8d53be87 authored by nanahira's avatar nanahira

update nat score

parent 39c589b3
...@@ -23,6 +23,7 @@ class InventoryBuilder { ...@@ -23,6 +23,7 @@ class InventoryBuilder {
async loadGateways() { async loadGateways() {
const gateways = await this.load('gateways2'); const gateways = await this.load('gateways2');
for (let gateway of gateways) { for (let gateway of gateways) {
gateway.isCN = this.hosts[gateway.router].location.startsWith("CN");
if (gateway.mark) { if (gateway.mark) {
gateway.selectionMark = gateway.mark + 50; gateway.selectionMark = gateway.mark + 50;
} else { } else {
...@@ -231,21 +232,23 @@ class InventoryBuilder { ...@@ -231,21 +232,23 @@ class InventoryBuilder {
// frps还是frpc的积分,NAT越有利分越高 // frps还是frpc的积分,NAT越有利分越高
gatewayCompareScore(gateway: any): number { gatewayCompareScore(gateway: any): number {
let score: number = 0xff - gateway.id; let score: number = 0xff - gateway.id; // 8 bits
const ipv4Score = ({ const isCNScore = gateway.isCN ? 1 : 0; // 1 bit
"static": 2, score |= isCNScore << 8;
"dynamic": 1 const ipv4NatScore = ({ // 2 bits
})[gateway.ipv4] || 0;
score |= ipv4Score << 12;
const ipv4NatScore = ({
"ports": 0, "ports": 0,
"dmz": 1 "dmz": 1
})[gateway.ipv4Nat] || 2; })[gateway.ipv4Nat] || 2;
score |= ipv4NatScore << 10; score |= ipv4NatScore << 9;
const globalSSHScore = ({ const ipv4Score = ({ // 2 bits
"static": 2,
"dynamic": 1
})[gateway.ipv4] || 0;
score |= ipv4Score << 11;
const globalSSHScore = ({ // 1 bit
"globalssh": 1 "globalssh": 1
})[gateway.ssh] || 0; })[gateway.ssh] || 0;
score |= globalSSHScore << 13; score |= globalSSHScore << 12;
return score; return score;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment