Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
240 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ nbactions.xml | |
/apl-exec/apl.log | ||
**/apl.log | ||
**/pom.xml.versionsBackup | ||
/apl-core/nbproject/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
apl-core/src/main/java/com/apollocurrency/aplwallet/apl/core/peer/PeerAddress.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright © 2018-2019 Apollo Foundation | ||
*/ | ||
package com.apollocurrency.aplwallet.apl.core.peer; | ||
|
||
import com.apollocurrency.aplwallet.apl.util.Constants; | ||
import com.apollocurrency.aplwallet.apl.util.injectable.PropertiesHolder; | ||
import java.net.Inet6Address; | ||
import java.net.InetAddress; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.net.UnknownHostException; | ||
|
||
/** | ||
* | ||
* @author alukin@gmail.com | ||
*/ | ||
public class PeerAddress { | ||
private InetAddress host; | ||
private String hostName; | ||
private Integer port; | ||
private final PropertiesHolder propertiesHolder; | ||
|
||
|
||
public PeerAddress(PropertiesHolder propertiesHolder) { | ||
this.propertiesHolder = propertiesHolder; | ||
try { | ||
host = InetAddress.getByName("127.0.0.1"); | ||
} catch (UnknownHostException ex) { | ||
} | ||
port = getDefaultPeerPort(); | ||
} | ||
|
||
public final Integer getDefaultPeerPort() { | ||
return propertiesHolder.getIntProperty("apl.networkPeerServerPort", Constants.DEFAULT_PEER_PORT); | ||
} | ||
|
||
public void fromString(String addr){ | ||
try { | ||
String a=addr.toLowerCase(); | ||
if(!a.startsWith("http")){ | ||
a="http://"+a; | ||
} | ||
URL u = new URL(a); | ||
host=InetAddress.getByName(u.getHost()); | ||
port=u.getPort(); | ||
if(port==-1){ | ||
port=getDefaultPeerPort(); | ||
} | ||
} catch (MalformedURLException | UnknownHostException ex) { | ||
} | ||
} | ||
|
||
public String getHost() { | ||
return host.getHostAddress(); | ||
} | ||
|
||
public void setHost(String host){ | ||
hostName=host; | ||
try { | ||
this.host = InetAddress.getByName(host); | ||
} catch (UnknownHostException ex) { | ||
} | ||
} | ||
|
||
public Integer getPort() { | ||
return port; | ||
} | ||
|
||
public void setPort(Integer port) { | ||
this.port = port; | ||
} | ||
|
||
public String getAddrWithPort(){ | ||
if (host instanceof Inet6Address){ | ||
return "["+host.getHostAddress()+"]:"+port.toString(); | ||
} else{ | ||
return host.getHostAddress()+":"+port.toString(); | ||
} | ||
} | ||
public InetAddress getInetAddress(){ | ||
return host; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.