Add GitHub workflow
This commit is contained in:
parent
69eea2ebf4
commit
a1c6a29eea
6 changed files with 47 additions and 23 deletions
16
.github/workflows/docker-image.yml
vendored
Normal file
16
.github/workflows/docker-image.yml
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
name: Docker Image CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["**"]
|
||||
pull_request:
|
||||
branches: ["**"]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Build the Docker image
|
||||
run: docker build . --file Dockerfile --tag my-image-name:$(date +%s)
|
8
pom.xml
8
pom.xml
|
@ -13,7 +13,7 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<version>3.7.0</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
|
@ -39,11 +39,7 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
<version>3.13.0</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
|
|
@ -14,6 +14,8 @@ import java.io.InputStream;
|
|||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
@ -23,17 +25,16 @@ public class HTTPHandler extends ChannelInboundHandlerAdapter{
|
|||
|
||||
public static final AttributeKey<HttpRequest> ATTR_REQUEST = AttributeKey.newInstance("request");
|
||||
public static final AttributeKey<List<HttpContent>> ATTR_CONTENT = AttributeKey.newInstance("content");
|
||||
private static final Logger LOGGER = Logger.getLogger("Handler");
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx,Object msg){
|
||||
if(msg instanceof HttpRequest){
|
||||
HttpRequest request = (HttpRequest) msg;
|
||||
ctx.channel().attr(HTTPHandler.ATTR_REQUEST).set(request);
|
||||
ctx.channel().attr(HTTPHandler.ATTR_REQUEST).set((HttpRequest) msg);
|
||||
}
|
||||
if(msg instanceof HttpContent){
|
||||
HttpContent content = (HttpContent) msg;
|
||||
ctx.channel().attr(HTTPHandler.ATTR_CONTENT).setIfAbsent(new ArrayList<>());
|
||||
ctx.channel().attr(HTTPHandler.ATTR_CONTENT).get().add(content);
|
||||
ctx.channel().attr(HTTPHandler.ATTR_CONTENT).get().add((HttpContent) msg);
|
||||
|
||||
if(msg instanceof LastHttpContent){
|
||||
this.handleResponse(ctx);
|
||||
|
@ -47,6 +48,8 @@ public class HTTPHandler extends ChannelInboundHandlerAdapter{
|
|||
ctx.channel().attr(HTTPHandler.ATTR_REQUEST).set(null);
|
||||
ctx.channel().attr(HTTPHandler.ATTR_CONTENT).set(null);
|
||||
|
||||
assert content!=null;
|
||||
|
||||
if(request.method().equals(HttpMethod.GET)){
|
||||
URI uri = URI.create(request.uri());
|
||||
|
||||
|
@ -118,7 +121,7 @@ public class HTTPHandler extends ChannelInboundHandlerAdapter{
|
|||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause){
|
||||
cause.printStackTrace(); //TODO
|
||||
HTTPHandler.LOGGER.log(Level.WARNING,"Exception during HTTP handling",cause);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ public class Node{
|
|||
private final InetAddress address;
|
||||
private Double latitude;
|
||||
private Double longitude;
|
||||
private List<Service> services = new ArrayList<>();
|
||||
private final List<Service> services = new ArrayList<>();
|
||||
|
||||
public Node(InetAddress address,Double latitude,Double longitude){
|
||||
this.address = address;
|
||||
|
@ -25,10 +25,18 @@ public class Node{
|
|||
return this.latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(Double latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public Double getLongitude() {
|
||||
return this.longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(Double longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public List<Service> getServices(){
|
||||
return this.services;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.io.InputStream;
|
|||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
import java.util.*;
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
@ -22,7 +22,7 @@ public class BlockchainNodeFinderThread implements Runnable{
|
|||
public void run() {
|
||||
while(true){
|
||||
try{
|
||||
HttpURLConnection conn = (HttpURLConnection) new URL(System.getenv("BLOCKCHAIN_RPC_URL")).openConnection();
|
||||
HttpURLConnection conn = (HttpURLConnection) new URI(System.getenv("BLOCKCHAIN_RPC_URL")).toURL().openConnection();
|
||||
conn.setDoOutput(true);
|
||||
conn.addRequestProperty("Authorization","Basic "+ Base64.getEncoder().encodeToString((System.getenv("BLOCKCHAIN_USERNAME")+":"+System.getenv("BLOCKCHAIN_PASSWORD")).getBytes()));
|
||||
conn.connect();
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
package com.lbry.globe.util;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URL;
|
||||
import java.net.*;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class GeoIP{
|
||||
|
||||
private static final Map<InetAddress,JSONObject> CACHE = new TreeMap<>(Comparator.comparing(InetAddress::getHostAddress));
|
||||
private static final Logger LOGGER = Logger.getLogger("GeoIP");
|
||||
private static final String TOKEN = System.getenv("IPINFO_TOKEN");
|
||||
|
||||
public static JSONObject getCachedGeoIPInformation(InetAddress ip){
|
||||
|
@ -23,14 +24,14 @@ public class GeoIP{
|
|||
GeoIP.CACHE.put(ip,result);
|
||||
GeoIP.saveCache();
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
GeoIP.LOGGER.log(Level.WARNING,"Failed getting cached GeoIP information.",e);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static JSONObject getGeoIPInformation(InetAddress ip) throws IOException{
|
||||
HttpURLConnection conn = (HttpURLConnection) new URL("https://ipinfo.io/"+ip.getHostAddress()+"?token="+GeoIP.TOKEN).openConnection();
|
||||
public static JSONObject getGeoIPInformation(InetAddress ip) throws IOException,URISyntaxException{
|
||||
HttpURLConnection conn = (HttpURLConnection) new URI("https://ipinfo.io/"+ip.getHostAddress()+"?token="+GeoIP.TOKEN).toURL().openConnection();
|
||||
conn.connect();
|
||||
InputStream in = conn.getInputStream();
|
||||
if(in==null){
|
||||
|
@ -68,7 +69,7 @@ public class GeoIP{
|
|||
}
|
||||
br.close();
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
GeoIP.LOGGER.log(Level.WARNING,"Failed loading GeoIP cache.",e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,7 +83,7 @@ public class GeoIP{
|
|||
fos.write(obj.toString().getBytes());
|
||||
fos.close();
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
GeoIP.LOGGER.log(Level.WARNING,"Failed saving GeoIP cache.",e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue