Skip to content

Commit

Permalink
ScionSocketAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
Tilmann Zäschke committed Jun 19, 2024
1 parent 4569d41 commit 79f04af
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 28 deletions.
8 changes: 4 additions & 4 deletions src/main/java/org/scion/jpan/ScionDatagramChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public boolean isBlocking() {
return super.isBlocking();
}

public ScionResponseAddress receive(ByteBuffer userBuffer) throws IOException {
public ScionSocketAddress receive(ByteBuffer userBuffer) throws IOException {
readLock().lock();
try {
ByteBuffer buffer = getBufferReceive(userBuffer.capacity());
Expand All @@ -85,7 +85,7 @@ public ScionResponseAddress receive(ByteBuffer userBuffer) throws IOException {
}
ScionHeaderParser.extractUserPayload(buffer, userBuffer);
buffer.clear();
return ScionResponseAddress.from(receivePath);
return ScionSocketAddress.from(receivePath);
} finally {
readLock().unlock();
}
Expand All @@ -108,8 +108,8 @@ public int send(ByteBuffer srcBuffer, SocketAddress destination) throws IOExcept
if (!(destination instanceof InetSocketAddress)) {
throw new IllegalArgumentException("Address must be of type InetSocketAddress.");
}
if (destination instanceof ScionResponseAddress) {
return send(srcBuffer, ((ScionResponseAddress) destination).getPath(), RefreshPolicy.OFF);
if (destination instanceof ScionSocketAddress) {
return send(srcBuffer, ((ScionSocketAddress) destination).getPath(), RefreshPolicy.OFF);
}

InetSocketAddress dst = (InetSocketAddress) destination;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/scion/jpan/ScionDatagramSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public synchronized void receive(DatagramPacket packet) throws IOException {
synchronized (packet) {
ByteBuffer receiveBuffer =
ByteBuffer.wrap(packet.getData(), packet.getOffset(), packet.getLength());
ScionResponseAddress responseAddress = channel.receive(receiveBuffer);
ScionSocketAddress responseAddress = channel.receive(receiveBuffer);
if (responseAddress == null) {
// timeout occurred
throw new SocketTimeoutException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

import java.net.InetSocketAddress;

public class ScionResponseAddress extends InetSocketAddress {
public class ScionSocketAddress extends InetSocketAddress {

private final ResponsePath responsePath;

public static ScionResponseAddress from(ResponsePath path) {
return new ScionResponseAddress(path);
public static ScionSocketAddress from(ResponsePath path) {
return new ScionSocketAddress(path);
}

private ScionResponseAddress(ResponsePath path) {
private ScionSocketAddress(ResponsePath path) {
super(path.getRemoteAddress(), path.getRemotePort());
this.responsePath = path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.util.Iterator;
import org.scion.jpan.ResponsePath;
import org.scion.jpan.ScionDatagramChannel;
import org.scion.jpan.ScionResponseAddress;
import org.scion.jpan.ScionSocketAddress;
import org.scion.jpan.ScionService;

/**
Expand Down Expand Up @@ -90,7 +90,7 @@ private ResponsePath receiveFromTimeoutChannel(
}

@Override
public ScionResponseAddress receive(ByteBuffer userBuffer) throws IOException {
public ScionSocketAddress receive(ByteBuffer userBuffer) throws IOException {
readLock().lock();
try {
ByteBuffer buffer = getBufferReceive(userBuffer.capacity());
Expand All @@ -100,7 +100,7 @@ public ScionResponseAddress receive(ByteBuffer userBuffer) throws IOException {
}
ScionHeaderParser.extractUserPayload(buffer, userBuffer);
buffer.clear();
return ScionResponseAddress.from(receivePath);
return ScionSocketAddress.from(receivePath);
} finally {
readLock().unlock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.scion.jpan.ScionDatagramChannel;
import org.scion.jpan.ScionResponseAddress;
import org.scion.jpan.ScionSocketAddress;
import org.scion.jpan.ScionService;
import org.scion.jpan.testutil.MockDNS;
import org.scion.jpan.testutil.MockDaemon;
Expand Down Expand Up @@ -128,7 +128,7 @@ private void concurrentReceive(Reader c1, Reader c2, Writer w1, boolean connect)
}

// check that receive is responsive
ScionResponseAddress responseAddress = server.receive(buffer);
ScionSocketAddress responseAddress = server.receive(buffer);
server.send(buffer, responseAddress);
// wait
synchronized (receiveCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void receive_withoutService() throws IOException {
try (ScionDatagramChannel channel = ScionDatagramChannel.open(null, mock)) {
assertNull(channel.getService());
ByteBuffer buffer = ByteBuffer.allocate(100);
ScionResponseAddress responseAddress = channel.receive(buffer);
ScionSocketAddress responseAddress = channel.receive(buffer);
assertNull(channel.getService());
assertEquals(addr, responseAddress.getPath().getFirstHopAddress());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.junit.jupiter.api.Test;
import org.scion.jpan.Path;
import org.scion.jpan.ScionDatagramChannel;
import org.scion.jpan.ScionResponseAddress;
import org.scion.jpan.ScionSocketAddress;
import org.scion.jpan.ScionService;
import org.scion.jpan.testutil.PingPongChannelHelper;

Expand Down Expand Up @@ -57,7 +57,7 @@ private void client(ScionDatagramChannel channel, Path serverAddress, int id) th

// System.out.println("CLIENT: Receiving ... (" + channel.getLocalAddress() + ")");
ByteBuffer response = ByteBuffer.allocate(512);
ScionResponseAddress address = channel.receive(response);
ScionSocketAddress address = channel.receive(response);
assertNotNull(address);
assertEquals(serverAddress.getRemoteAddress(), address.getPath().getRemoteAddress());
assertEquals(serverAddress.getRemotePort(), address.getPath().getRemotePort());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.junit.jupiter.api.Test;
import org.scion.jpan.Path;
import org.scion.jpan.ScionDatagramChannel;
import org.scion.jpan.ScionResponseAddress;
import org.scion.jpan.ScionSocketAddress;
import org.scion.jpan.ScionService;
import org.scion.jpan.testutil.PingPongChannelHelper;

Expand Down Expand Up @@ -51,7 +51,7 @@ private void client(ScionDatagramChannel channel, Path serverAddress, int id) th

// System.out.println("CLIENT: Receiving ... (" + channel.getLocalAddress() + ")");
ByteBuffer response = ByteBuffer.allocate(512);
ScionResponseAddress address = channel.receive(response);
ScionSocketAddress address = channel.receive(response);
assertNotNull(address);
assertEquals(serverAddress.getRemoteAddress(), address.getAddress());
assertEquals(serverAddress.getRemotePort(), address.getPort());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void client(ScionDatagramChannel channel, RequestPath serverAddress, int
private void server(ScionDatagramChannel channel) throws IOException {
ByteBuffer request = ByteBuffer.allocate(512);
// System.out.println("SERVER: --- USER - Waiting for packet --------------------- " + i);
ScionResponseAddress responseAddress = channel.receive(request);
ScionSocketAddress responseAddress = channel.receive(request);

request.flip();
String msg = Charset.defaultCharset().decode(request).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.junit.jupiter.api.Test;
import org.scion.jpan.Path;
import org.scion.jpan.ScionDatagramChannel;
import org.scion.jpan.ScionResponseAddress;
import org.scion.jpan.ScionSocketAddress;
import org.scion.jpan.ScionService;
import org.scion.jpan.testutil.MockNetwork;
import org.scion.jpan.testutil.PingPongChannelHelper;
Expand Down Expand Up @@ -72,10 +72,10 @@ private void client(ScionDatagramChannel channel, Path serverAddress, int id) th
}

private static class Pair {
ScionResponseAddress responseAddress;
ScionSocketAddress responseAddress;
String msg;

Pair(ScionResponseAddress responseAddress, String msg) {
Pair(ScionSocketAddress responseAddress, String msg) {
this.responseAddress = responseAddress;
this.msg = msg;
}
Expand All @@ -89,7 +89,7 @@ public void server(ScionDatagramChannel channel) throws IOException {
ArrayList<Pair> received = new ArrayList<>();
for (int i = 0; i < N_BULK; i++) {
request.clear();
ScionResponseAddress responseAddress = channel.receive(request);
ScionSocketAddress responseAddress = channel.receive(request);
request.flip();
String msg = Charset.defaultCharset().decode(request).toString();
received.add(new Pair(responseAddress, msg));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private static void service() throws IOException {
channel.bind(SERVER_ADDRESS);
ByteBuffer buffer = ByteBuffer.allocate(100);
println("Waiting for packet ... ");
ScionResponseAddress responseAddress = channel.receive(buffer);
ScionSocketAddress responseAddress = channel.receive(buffer);
ResponsePath path = responseAddress.getPath();
String msg = extractMessage(buffer);
String remoteAddress = path.getRemoteAddress() + ":" + path.getRemotePort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.scion.jpan.Path;
import org.scion.jpan.RequestPath;
import org.scion.jpan.ScionDatagramChannel;
import org.scion.jpan.ScionResponseAddress;
import org.scion.jpan.ScionSocketAddress;

public class PingPongChannelHelper extends PingPongHelperBase {

Expand Down Expand Up @@ -137,7 +137,7 @@ public static void defaultClient(ScionDatagramChannel channel, Path serverAddres

// System.out.println("CLIENT: Receiving ... (" + channel.getLocalAddress() + ")");
ByteBuffer response = ByteBuffer.allocate(512);
ScionResponseAddress address = channel.receive(response);
ScionSocketAddress address = channel.receive(response);
assertNotNull(address);
assertEquals(serverAddress.getRemoteAddress(), address.getAddress());
assertEquals(serverAddress.getRemotePort(), address.getPort());
Expand All @@ -150,7 +150,7 @@ public static void defaultClient(ScionDatagramChannel channel, Path serverAddres
public static void defaultServer(ScionDatagramChannel channel) throws IOException {
ByteBuffer request = ByteBuffer.allocate(512);
// System.out.println("SERVER: Receiving ... (" + channel.getLocalAddress() + ")");
ScionResponseAddress responseAddress = channel.receive(request);
ScionSocketAddress responseAddress = channel.receive(request);

request.flip();
String msg = Charset.defaultCharset().decode(request).toString();
Expand Down

0 comments on commit 79f04af

Please sign in to comment.