Commit be1da044 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

[enh] Add GVA and GVASUB API to endpoint parser

parent 5a449bcf
Pipeline #10553 passed with stage
in 45 seconds
......@@ -37,6 +37,8 @@ public enum EndpointApi implements IEndpointApi {
BMATOR(),
WS2P(),
WS2PTOR(),
GVA(),
GVASUB(),
ES_CORE_API(),
ES_USER_API(),
ES_SUBSCRIPTION_API(),
......
......@@ -46,11 +46,15 @@ public class Endpoints {
public static final String BMA_API_REGEXP = "^BASIC_MERKLED_API" + EP_END_REGEXP;
public static final String BMAS_API_REGEXP = "^BMAS" + EP_END_REGEXP;
public static final String WS2P_API_REGEXP = "^(WS2P(?:TOR)?) ([a-f0-9]{7,8})" + EP_END_REGEXP;
public static final String GVA_API_REGEXP = "^GVA(:? S)?" + EP_END_REGEXP;
public static final String GVASUB_API_REGEXP = "^GVASUB(:? S)?" + EP_END_REGEXP;
public static final String OTHER_API_REGEXP = "^([A-Z_-]+)" + EP_END_REGEXP;
private static Pattern bmaPattern = Pattern.compile(BMA_API_REGEXP);
private static Pattern bmasPattern = Pattern.compile(BMAS_API_REGEXP);
private static Pattern ws2pPattern = Pattern.compile(WS2P_API_REGEXP);
private static Pattern gvaPattern = Pattern.compile(GVA_API_REGEXP);
private static Pattern gvaSubPattern = Pattern.compile(GVASUB_API_REGEXP);
private static Pattern otherApiPattern = Pattern.compile(OTHER_API_REGEXP);
private Endpoints() {
......@@ -62,8 +66,49 @@ public class Endpoints {
NetworkPeering.Endpoint endpoint = new NetworkPeering.Endpoint();
endpoint.setRaw(raw);
// WS2P API
Matcher mather = ws2pPattern.matcher(raw);
if (mather.matches()) {
String api = mather.group(1);
try {
endpoint.api = EndpointApi.valueOf(api).label();
endpoint.id = mather.group(2);
parseDefaultFormatEndPoint(mather, endpoint, 3);
return Optional.of(endpoint);
} catch(Exception e) {
// Unknown API
throw new IOException("Unable to deserialize endpoint: WS2P api [" + api + "]", e); // link the exception
}
}
// GVA API
mather = gvaPattern.matcher(raw);
if (mather.matches()) {
endpoint.api = EndpointApi.GVA.label();
try {
parseDefaultFormatEndPoint(mather, endpoint, 2);
return Optional.of(endpoint);
} catch(Exception e) {
// Unknown API
throw new IOException("Unable to deserialize endpoint: api [" + endpoint.api + "]", e); // link the exception
}
}
// GVA SUB API
mather = gvaSubPattern.matcher(raw);
if (mather.matches()) {
endpoint.api = EndpointApi.GVASUB.label();
try {
parseDefaultFormatEndPoint(mather, endpoint, 2);
return Optional.of(endpoint);
} catch(Exception e) {
// Unknown API
throw new IOException("Unable to deserialize endpoint: api [" + endpoint.api + "]", e); // link the exception
}
}
// BMA API
Matcher mather = bmaPattern.matcher(raw);
mather = bmaPattern.matcher(raw);
if (mather.matches()) {
endpoint.api = EndpointApi.BASIC_MERKLED_API.label();
parseDefaultFormatEndPoint(mather, endpoint, 1);
......@@ -78,21 +123,6 @@ public class Endpoints {
return Optional.of(endpoint);
}
// WS2P API
mather = ws2pPattern.matcher(raw);
if (mather.matches()) {
String api = mather.group(1);
try {
endpoint.api = EndpointApi.valueOf(api).label();
endpoint.id = mather.group(2);
parseDefaultFormatEndPoint(mather, endpoint, 3);
return Optional.of(endpoint);
} catch(Exception e) {
// Unknown API
throw new IOException("Unable to deserialize endpoint: WS2P api [" + api + "]", e); // link the exception
}
}
// Other API
mather = otherApiPattern.matcher(raw);
if (mather.matches()) {
......
......@@ -169,6 +169,7 @@ public class NetworkPeering implements Serializable {
public Integer port;
public String id;
public String path;
public Boolean useSsl;
public String raw;
public String getApi() {
......@@ -227,6 +228,14 @@ public class NetworkPeering implements Serializable {
this.path = path;
}
public Boolean useSsl() {
return useSsl;
}
public void setUseSsl(Boolean useSsl) {
this.useSsl = useSsl;
}
@JsonIgnore
public String getRaw() {
return raw;
......@@ -246,6 +255,10 @@ public class NetworkPeering implements Serializable {
if (api != null) {
joiner.add(api);
}
// SSL
if (useSsl != null && useSsl.booleanValue()) {
joiner.add("S"); // useSsl ? used by GVA or GVASUB
}
// Id (use for WS2P)
if (StringUtils.isNotBlank(id)) {
joiner.add(id);
......@@ -277,6 +290,7 @@ public class NetworkPeering implements Serializable {
public boolean equals(Object obj) {
if (obj instanceof Endpoint) {
return Objects.equals(((Endpoint) obj).api, api)
&& Objects.equals(((Endpoint) obj).useSsl, useSsl)
&& Objects.equals(((Endpoint) obj).id, id)
&& Objects.equals(((Endpoint) obj).dns, dns)
&& Objects.equals(((Endpoint) obj).ipv4, ipv4)
......
......@@ -62,6 +62,30 @@ public class EndpointsTest {
Assert.assertNotNull(ep.port);
Assert.assertEquals(20901, ep.port.intValue());
// GVA
ep = Endpoints.parse("GVA S g1.librelois.fr 443 gva").orElse(null);
Assert.assertNotNull(ep);
Assert.assertEquals(EndpointApi.GVA.label(), ep.api);
Assert.assertEquals("g1.librelois.fr", ep.dns);
Assert.assertNull(ep.ipv4);
Assert.assertNotNull(ep.port);
Assert.assertEquals(443, ep.port.intValue());
Assert.assertNull(ep.id);
Assert.assertEquals("gva", ep.path);
// GVA SUB
ep = Endpoints.parse("GVASUB S g1.librelois.fr 443 gva-sub").orElse(null);
Assert.assertNotNull(ep);
Assert.assertEquals(EndpointApi.GVASUB.label(), ep.api);
Assert.assertEquals("g1.librelois.fr", ep.dns);
Assert.assertNull(ep.ipv4);
Assert.assertNotNull(ep.port);
Assert.assertEquals(443, ep.port.intValue());
Assert.assertNull(ep.id);
Assert.assertEquals("gva-sub", ep.path);
// Any other api
ep = Endpoints.parse("GCHANGE_API data.gchange.fr 443").orElse(null);
Assert.assertNotNull(ep);
Assert.assertEquals(ep.api, "GCHANGE_API");
......
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