generated from codecrafters-io/course-template
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from urielsalis/java-support
Add java support
- Loading branch information
Showing
24 changed files
with
485 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto |
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,4 @@ | ||
java_dns.jar | ||
target/* | ||
target/ | ||
.idea/ |
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,37 @@ | ||
![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/dns-server.png) | ||
|
||
This is a starting point for Java solutions to the | ||
["Build Your Own DNS server" Challenge](https://app.codecrafters.io/courses/dns-server/overview). | ||
|
||
In this challenge, you'll build a DNS server that's capable of parsing and | ||
creating DNS packets, responding to DNS queries, handling various record types | ||
and doing recursive resolve. Along the way we'll learn about the DNS protocol, | ||
DNS packet format, root servers, authoritative servers, forwarding servers, | ||
various record types (A, AAAA, CNAME, etc) and more. | ||
|
||
**Note**: If you're viewing this repo on GitHub, head over to | ||
[codecrafters.io](https://codecrafters.io) to try the challenge. | ||
|
||
# Passing the first stage | ||
|
||
The entry point for your `your_server.sh` implementation is in | ||
`src/main/java/Main.java`. Study and uncomment the relevant code, and push your | ||
changes to pass the first stage: | ||
|
||
```sh | ||
git add . | ||
git commit -m "pass 1st stage" # any msg | ||
git push origin master | ||
``` | ||
|
||
Time to move on to the next stage! | ||
|
||
# Stage 2 & beyond | ||
|
||
Note: This section is for stages 2 and beyond. | ||
|
||
1. Ensure you have `java (21)` installed locally | ||
1. Run `./your_server.sh` to run your program, which is implemented in | ||
`src/main/java/Main.java`. | ||
1. Commit your changes and run `git push origin master` to submit your solution | ||
to CodeCrafters. Test output will be streamed to your terminal. |
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,11 @@ | ||
# Set this to true if you want debug logs. | ||
# | ||
# These can be VERY verbose, so we suggest turning them off | ||
# unless you really need them. | ||
debug: false | ||
|
||
# Use this to change the Java version used to run your code | ||
# on Codecrafters. | ||
# | ||
# Available versions: java-21 | ||
language_pack: java-21 |
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,52 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>io.codecrafters</groupId> | ||
<artifactId>build-your-own-dns</artifactId> | ||
<version>1.0</version> | ||
|
||
<properties> | ||
<maven.compiler.source>21</maven.compiler.source> | ||
<maven.compiler.target>21</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<java.version>21</java.version> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<configuration> | ||
<finalName>java_dns</finalName> <!-- Please do not change this final artifact name--> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
<appendAssemblyId>false</appendAssemblyId> | ||
<archive> | ||
<manifest> | ||
<addClasspath>true</addClasspath> | ||
<!-- This is the main class of your program which will be executed--> | ||
<mainClass>Main</mainClass> | ||
</manifest> | ||
</archive> | ||
<outputDirectory>${dir}</outputDirectory> | ||
</configuration> | ||
|
||
<executions> | ||
<execution> | ||
<id>make-assembly</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
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,27 @@ | ||
import java.io.IOException; | ||
import java.net.DatagramPacket; | ||
import java.net.DatagramSocket; | ||
|
||
public class Main { | ||
public static void main(String[] args){ | ||
// You can use print statements as follows for debugging, they'll be visible when running tests. | ||
System.out.println("Logs from your program will appear here!"); | ||
|
||
// Uncomment this block to pass the first stage | ||
// | ||
// while(true) { | ||
// try(DatagramSocket serverSocket = new DatagramSocket(2053)) { | ||
// final byte[] buf = new byte[512]; | ||
// final DatagramPacket packet = new DatagramPacket(buf, buf.length); | ||
// serverSocket.receive(packet); | ||
// System.out.println("Received data"); | ||
// | ||
// final byte[] bufResponse = new byte[512]; | ||
// final DatagramPacket packetResponse = new DatagramPacket(bufResponse, bufResponse.length, packet.getSocketAddress()); | ||
// serverSocket.send(packetResponse); | ||
// } catch (IOException e) { | ||
// System.out.println("IOException: " + e.getMessage()); | ||
// } | ||
// } | ||
} | ||
} |
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,10 @@ | ||
#!/bin/sh | ||
# | ||
# DON'T EDIT THIS! | ||
# | ||
# CodeCrafters uses this file to test your code. Don't make any changes here! | ||
# | ||
# DON'T EDIT THIS! | ||
set -e | ||
mvn -B --quiet package -Ddir=/tmp/codecrafters-dns-target | ||
exec java -jar /tmp/codecrafters-dns-target/java_dns.jar "$@" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM maven:3.9.5-eclipse-temurin-21-alpine | ||
|
||
COPY pom.xml /app/pom.xml | ||
|
||
WORKDIR /app | ||
|
||
# Download the dependencies | ||
RUN mvn -B package -Ddir=/tmp/codecrafters-dns-target | ||
|
||
# Cache Dependencies | ||
RUN mkdir -p /app-cached | ||
RUN mv /app/target /app-cached # Is this needed? | ||
|
||
# Pre-compile steps | ||
RUN echo "cd \${CODECRAFTERS_SUBMISSION_DIR} && mvn -B package -Ddir=/tmp/codecrafters-dns-target && sed -i 's/^\(mvn .*\)/#\1/' ./your_server.sh" > /codecrafters-precompile.sh | ||
RUN chmod +x /codecrafters-precompile.sh |
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 @@ | ||
* text=auto |
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,4 @@ | ||
java_dns.jar | ||
target/* | ||
target/ | ||
.idea/ |
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,37 @@ | ||
![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/dns-server.png) | ||
|
||
This is a starting point for Java solutions to the | ||
["Build Your Own DNS server" Challenge](https://app.codecrafters.io/courses/dns-server/overview). | ||
|
||
In this challenge, you'll build a DNS server that's capable of parsing and | ||
creating DNS packets, responding to DNS queries, handling various record types | ||
and doing recursive resolve. Along the way we'll learn about the DNS protocol, | ||
DNS packet format, root servers, authoritative servers, forwarding servers, | ||
various record types (A, AAAA, CNAME, etc) and more. | ||
|
||
**Note**: If you're viewing this repo on GitHub, head over to | ||
[codecrafters.io](https://codecrafters.io) to try the challenge. | ||
|
||
# Passing the first stage | ||
|
||
The entry point for your `your_server.sh` implementation is in | ||
`src/main/java/Main.java`. Study and uncomment the relevant code, and push your | ||
changes to pass the first stage: | ||
|
||
```sh | ||
git add . | ||
git commit -m "pass 1st stage" # any msg | ||
git push origin master | ||
``` | ||
|
||
Time to move on to the next stage! | ||
|
||
# Stage 2 & beyond | ||
|
||
Note: This section is for stages 2 and beyond. | ||
|
||
1. Ensure you have `java (21)` installed locally | ||
1. Run `./your_server.sh` to run your program, which is implemented in | ||
`src/main/java/Main.java`. | ||
1. Commit your changes and run `git push origin master` to submit your solution | ||
to CodeCrafters. Test output will be streamed to your terminal. |
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,11 @@ | ||
# Set this to true if you want debug logs. | ||
# | ||
# These can be VERY verbose, so we suggest turning them off | ||
# unless you really need them. | ||
debug: false | ||
|
||
# Use this to change the Java version used to run your code | ||
# on Codecrafters. | ||
# | ||
# Available versions: java-21 | ||
language_pack: java-21 |
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,52 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>io.codecrafters</groupId> | ||
<artifactId>build-your-own-dns</artifactId> | ||
<version>1.0</version> | ||
|
||
<properties> | ||
<maven.compiler.source>21</maven.compiler.source> | ||
<maven.compiler.target>21</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<java.version>21</java.version> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<configuration> | ||
<finalName>java_dns</finalName> <!-- Please do not change this final artifact name--> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
<appendAssemblyId>false</appendAssemblyId> | ||
<archive> | ||
<manifest> | ||
<addClasspath>true</addClasspath> | ||
<!-- This is the main class of your program which will be executed--> | ||
<mainClass>Main</mainClass> | ||
</manifest> | ||
</archive> | ||
<outputDirectory>${dir}</outputDirectory> | ||
</configuration> | ||
|
||
<executions> | ||
<execution> | ||
<id>make-assembly</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
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,22 @@ | ||
import java.io.IOException; | ||
import java.net.DatagramPacket; | ||
import java.net.DatagramSocket; | ||
|
||
public class Main { | ||
public static void main(String[] args){ | ||
while(true) { | ||
try(DatagramSocket serverSocket = new DatagramSocket(2053)) { | ||
final byte[] buf = new byte[512]; | ||
final DatagramPacket packet = new DatagramPacket(buf, buf.length); | ||
serverSocket.receive(packet); | ||
System.out.println("Received data"); | ||
|
||
final byte[] bufResponse = new byte[512]; | ||
final DatagramPacket packetResponse = new DatagramPacket(bufResponse, bufResponse.length, packet.getSocketAddress()); | ||
serverSocket.send(packetResponse); | ||
} catch (IOException e) { | ||
System.out.println("IOException: " + e.getMessage()); | ||
} | ||
} | ||
} | ||
} |
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,10 @@ | ||
#!/bin/sh | ||
# | ||
# DON'T EDIT THIS! | ||
# | ||
# CodeCrafters uses this file to test your code. Don't make any changes here! | ||
# | ||
# DON'T EDIT THIS! | ||
set -e | ||
mvn -B --quiet package -Ddir=/tmp/codecrafters-dns-target | ||
exec java -jar /tmp/codecrafters-dns-target/java_dns.jar "$@" |
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,41 @@ | ||
@@ -1,27 +1,22 @@ | ||
import java.io.IOException; | ||
import java.net.DatagramPacket; | ||
import java.net.DatagramSocket; | ||
|
||
public class Main { | ||
public static void main(String[] args){ | ||
- // You can use print statements as follows for debugging, they'll be visible when running tests. | ||
- System.out.println("Logs from your program will appear here!"); | ||
+ while(true) { | ||
+ try(DatagramSocket serverSocket = new DatagramSocket(2053)) { | ||
+ final byte[] buf = new byte[512]; | ||
+ final DatagramPacket packet = new DatagramPacket(buf, buf.length); | ||
+ serverSocket.receive(packet); | ||
+ System.out.println("Received data"); | ||
|
||
- // Uncomment this block to pass the first stage | ||
- // | ||
- // while(true) { | ||
- // try(DatagramSocket serverSocket = new DatagramSocket(2053)) { | ||
- // final byte[] buf = new byte[512]; | ||
- // final DatagramPacket packet = new DatagramPacket(buf, buf.length); | ||
- // serverSocket.receive(packet); | ||
- // System.out.println("Received data"); | ||
- // | ||
- // final byte[] bufResponse = new byte[512]; | ||
- // final DatagramPacket packetResponse = new DatagramPacket(bufResponse, bufResponse.length, packet.getSocketAddress()); | ||
- // serverSocket.send(packetResponse); | ||
- // } catch (IOException e) { | ||
- // System.out.println("IOException: " + e.getMessage()); | ||
- // } | ||
- // } | ||
+ final byte[] bufResponse = new byte[512]; | ||
+ final DatagramPacket packetResponse = new DatagramPacket(bufResponse, bufResponse.length, packet.getSocketAddress()); | ||
+ serverSocket.send(packetResponse); | ||
+ } catch (IOException e) { | ||
+ System.out.println("IOException: " + e.getMessage()); | ||
+ } | ||
+ } | ||
} | ||
} |
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,30 @@ | ||
The entry point for your dns implementation is in `src/main/java/Main.java`. | ||
|
||
Study and uncomment the relevant code: | ||
|
||
```java | ||
// Uncomment this block to pass the first stage | ||
|
||
while(true) { | ||
try(DatagramSocket serverSocket = new DatagramSocket(2053)) { | ||
final byte[] buf = new byte[512]; | ||
final DatagramPacket packet = new DatagramPacket(buf, buf.length); | ||
serverSocket.receive(packet); | ||
System.out.println("Received data"); | ||
|
||
final byte[] bufResponse = new byte[512]; | ||
final DatagramPacket packetResponse = new DatagramPacket(bufResponse, bufResponse.length, packet.getSocketAddress()); | ||
serverSocket.send(packetResponse); | ||
} catch (IOException e) { | ||
System.out.println("IOException: " + e.getMessage()); | ||
} | ||
} | ||
``` | ||
|
||
Push your changes to pass the first stage: | ||
|
||
``` | ||
git add . | ||
git commit -m "pass 1st stage" # any msg | ||
git push origin master | ||
``` |
Oops, something went wrong.