Skip to content

Commit

Permalink
Further refinement of lookup result error handling with actionable me…
Browse files Browse the repository at this point in the history
…ssages
  • Loading branch information
aaron-kumar committed Aug 31, 2024
1 parent 69c1804 commit 9540e20
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public BdxlLocator(Mode mode) {
CLOUDFLARE_PRIMARY_DNS = InetAddress.getByAddress((new byte[]{(byte) (1 & 0xff), (byte) (1 & 0xff), (byte) (1 & 0xff), (byte) (1 & 0xff)}));
CLOUDFLARE_SECONDARY_DNS = InetAddress.getByAddress((new byte[]{(byte) (1 & 0xff), (byte) (0 & 0xff), (byte) (0 & 0xff), (byte) (1 & 0xff)}));
} catch (UnknownHostException e) {
//Unable to initialize Custom DNS server Primary DNS lookup fail, now try with default resolver
//Unable to initialize Custom DNS server
}

customDNSServers.add(GOOGLE_PRIMARY_DNS);
Expand Down Expand Up @@ -161,10 +161,14 @@ public URI lookup(ParticipantIdentifier participantIdentifier) throws LookupExce

if (naptrLookup.getResult() != Lookup.SUCCESSFUL) {
switch (naptrLookup.getResult()) {
case Lookup.HOST_NOT_FOUND: // HOST_NOT_FOUND = The host does not exist
case Lookup.TYPE_NOT_FOUND: // TYPE_NOT_FOUND = The host exists, but has no records associated with the queried type
throw new NotFoundException(String.format("Identifier '%s' is not registered in SML.", participantIdentifier.getIdentifier()));
case Lookup.TRY_AGAIN: // Since we already tried a couple of times with TRY_AGAIN for TCP and UDP, now giving up ...
case Lookup.HOST_NOT_FOUND: // The host does not exist
throw new NotFoundException(String.format("Identifier '%s' is not registered in SML. The host '%s' does not exist", participantIdentifier.getIdentifier(), hostname));
case Lookup.TYPE_NOT_FOUND: // The host exists, but has no records associated with the queried type
throw new NotFoundException(String.format("Identifier '%s' is not registered in SML. The Host '%s' exists, but has no records associated with the queried type", participantIdentifier.getIdentifier(), hostname));
case Lookup.TRY_AGAIN: // The lookup failed due to a network error. Repeating the lookup may be helpful.
throw new LookupException(String.format("Error when looking up identifier '%s' in SML due to network error. Retry after sometime... DNS-Lookup-Err: %s", participantIdentifier.getIdentifier(), naptrLookup.getErrorString()));
case Lookup.UNRECOVERABLE: // The lookup failed due to a data or server error. Repeating the lookup would not be helpful.
throw new LookupException(String.format("Error when looking up identifier '%s' in SML due to a data or server error. Repeating the lookup immediately would not be helpful. DNS-Lookup-Err: %s", participantIdentifier.getIdentifier(), naptrLookup.getErrorString()));
default:
throw new LookupException(String.format("Error when looking up identifier '%s' in SML. DNS-Lookup-Err: %s", participantIdentifier.getIdentifier(), naptrLookup.getErrorString()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ public BusdoxLocator(Mode mode) {

CLOUDFLARE_PRIMARY_DNS = InetAddress.getByAddress((new byte[]{(byte) (1 & 0xff), (byte) (1 & 0xff), (byte) (1 & 0xff), (byte) (1 & 0xff)}));
CLOUDFLARE_SECONDARY_DNS = InetAddress.getByAddress((new byte[]{(byte) (1 & 0xff), (byte) (0 & 0xff), (byte) (0 & 0xff), (byte) (1 & 0xff)}));
// CLOUDFLARE_SECONDARY_DNS = InetAddress.getByAddress((new byte[]{(byte) (1 & 0xff), (byte) (0), (byte) (0), (byte) (1 & 0xff)}));
} catch (UnknownHostException e) {
//Unable to initialize Custom DNS server Primary DNS lookup fail, now try with default resolver
//Unable to initialize Custom DNS server
}

customDNSServers.add(GOOGLE_PRIMARY_DNS);
Expand Down Expand Up @@ -99,7 +98,7 @@ public URI lookup(ParticipantIdentifier participantIdentifier) throws LookupExce
lookup.setResolver(extendedResolver);

int retryCountLeft = maxRetries;
// Retry = The lookup may fail due to a network error. Repeating the lookup might be helpful
// Retry, The lookup may fail due to a network error. Repeating the lookup might be helpful
do {
lookup.run();
--retryCountLeft;
Expand All @@ -118,10 +117,14 @@ public URI lookup(ParticipantIdentifier participantIdentifier) throws LookupExce

if (lookup.getResult() != Lookup.SUCCESSFUL) {
switch (lookup.getResult()) {
case Lookup.HOST_NOT_FOUND: // HOST_NOT_FOUND = The host does not exist
case Lookup.TYPE_NOT_FOUND: // TYPE_NOT_FOUND = The host exists, but has no records associated with the queried type
throw new NotFoundException(String.format("Identifier '%s' is not registered in SML.", participantIdentifier.getIdentifier()));
case Lookup.TRY_AGAIN: // Since we already tried a couple of times with TRY_AGAIN for TCP and UDP, now giving up ...
case Lookup.HOST_NOT_FOUND: // The host does not exist
throw new NotFoundException(String.format("Identifier '%s' is not registered in SML. The host '%s' does not exist", participantIdentifier.getIdentifier(), hostname));
case Lookup.TYPE_NOT_FOUND: // The host exists, but has no records associated with the queried type
throw new NotFoundException(String.format("Identifier '%s' is not registered in SML. The Host '%s' exists, but has no records associated with the queried type", participantIdentifier.getIdentifier(), hostname));
case Lookup.TRY_AGAIN: // The lookup failed due to a network error. Repeating the lookup may be helpful.
throw new LookupException(String.format("Error when looking up identifier '%s' in SML due to network error. Retry after sometime... DNS-Lookup-Err: %s", participantIdentifier.getIdentifier(), lookup.getErrorString()));
case Lookup.UNRECOVERABLE: // The lookup failed due to a data or server error. Repeating the lookup would not be helpful.
throw new LookupException(String.format("Error when looking up identifier '%s' in SML due to a data or server error. Repeating the lookup immediately would not be helpful. DNS-Lookup-Err: %s", participantIdentifier.getIdentifier(), lookup.getErrorString()));
default:
throw new LookupException(String.format("Error when looking up identifier '%s' in SML. DNS-Lookup-Err: %s", participantIdentifier.getIdentifier(), lookup.getErrorString()));
}
Expand Down

0 comments on commit 9540e20

Please sign in to comment.