Add GitHub workflow

This commit is contained in:
Ben van Hartingsveldt 2024-12-02 11:20:42 +01:00
parent 69eea2ebf4
commit a1c6a29eea
No known key found for this signature in database
GPG key ID: 261AA214130CE7AB
6 changed files with 47 additions and 23 deletions

16
.github/workflows/docker-image.yml vendored Normal file
View 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)

View file

@ -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>

View file

@ -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());
@ -117,8 +120,8 @@ public class HTTPHandler extends ChannelInboundHandlerAdapter{
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
cause.printStackTrace(); //TODO
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause){
HTTPHandler.LOGGER.log(Level.WARNING,"Exception during HTTP handling",cause);
ctx.close();
}

View file

@ -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;
}

View file

@ -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();

View file

@ -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);
}
}