-
Notifications
You must be signed in to change notification settings - Fork 144
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
1 parent
c8e1d80
commit ff62fc1
Showing
15 changed files
with
309 additions
and
45 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
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,58 @@ | ||
package app.nzyme.core.ethernet.socks; | ||
|
||
import app.nzyme.core.NzymeNode; | ||
import app.nzyme.core.ethernet.Ethernet; | ||
import app.nzyme.core.ethernet.socks.db.SocksTunnelEntry; | ||
import app.nzyme.core.util.TimeRange; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public class Socks { | ||
|
||
private final NzymeNode nzyme; | ||
|
||
public Socks(Ethernet ethernet) { | ||
this.nzyme = ethernet.getNzyme(); | ||
} | ||
|
||
public long countAllSocksTunnels(TimeRange timeRange, List<UUID> taps) { | ||
if (taps.isEmpty()) { | ||
return 0; | ||
} | ||
|
||
return nzyme.getDatabase().withHandle(handle -> | ||
handle.createQuery("SELECT COUNT(*) FROM socks_tunnels " + | ||
"WHERE most_recent_segment_time >= :tr_from AND most_recent_segment_time <= :tr_to " + | ||
"AND tap_uuid IN (<taps>)") | ||
.bindList("taps", taps) | ||
.bind("tr_from", timeRange.from()) | ||
.bind("tr_to", timeRange.to()) | ||
.mapTo(Long.class) | ||
.one() | ||
); | ||
} | ||
|
||
public List<SocksTunnelEntry> findAllSocksTunnels(TimeRange timeRange, int limit, int offset, List<UUID> taps) { | ||
if (taps.isEmpty()) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
return nzyme.getDatabase().withHandle(handle -> | ||
handle.createQuery("SELECT * FROM socks_tunnels " + | ||
"WHERE most_recent_segment_time >= :tr_from AND most_recent_segment_time <= :tr_to " + | ||
"AND tap_uuid IN (<taps>) " + | ||
"ORDER BY most_recent_segment_time DESC " + | ||
"LIMIT :limit OFFSET :offset") | ||
.bindList("taps", taps) | ||
.bind("tr_from", timeRange.from()) | ||
.bind("tr_to", timeRange.to()) | ||
.bind("limit", limit) | ||
.bind("offset", offset) | ||
.mapTo(SocksTunnelEntry.class) | ||
.list() | ||
); | ||
} | ||
|
||
} |
101 changes: 101 additions & 0 deletions
101
src/main/java/app/nzyme/core/ethernet/socks/db/SocksTunnelEntry.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,101 @@ | ||
package app.nzyme.core.ethernet.socks.db; | ||
|
||
import com.google.auto.value.AutoValue; | ||
import jakarta.annotation.Nullable; | ||
import org.joda.time.DateTime; | ||
|
||
import java.util.UUID; | ||
|
||
@AutoValue | ||
public abstract class SocksTunnelEntry { | ||
|
||
public abstract long id(); | ||
public abstract UUID uuid(); | ||
public abstract UUID tapUuid(); | ||
public abstract String tcpSessionKey(); | ||
public abstract String socksType(); | ||
public abstract String authenticationStatus(); | ||
public abstract String handshakeStatus(); | ||
public abstract String connectionStatus(); | ||
@Nullable | ||
public abstract String username(); | ||
public abstract int tunneledBytes(); | ||
@Nullable | ||
public abstract String tunneledDestinationAddress(); | ||
@Nullable | ||
public abstract String tunneledDestinationHost(); | ||
public abstract int tunneledDestinationPort(); | ||
public abstract DateTime establishedAt(); | ||
public abstract DateTime terminatedAt(); | ||
public abstract DateTime mostRecentSegmentTime(); | ||
public abstract DateTime updatedAt(); | ||
public abstract DateTime createdAt(); | ||
|
||
public static SocksTunnelEntry create(long id, UUID uuid, UUID tapUuid, String tcpSessionKey, String socksType, String authenticationStatus, String handshakeStatus, String connectionStatus, String username, int tunneledBytes, String tunneledDestinationAddress, String tunneledDestinationHost, int tunneledDestinationPort, DateTime establishedAt, DateTime terminatedAt, DateTime mostRecentSegmentTime, DateTime updatedAt, DateTime createdAt) { | ||
return builder() | ||
.id(id) | ||
.uuid(uuid) | ||
.tapUuid(tapUuid) | ||
.tcpSessionKey(tcpSessionKey) | ||
.socksType(socksType) | ||
.authenticationStatus(authenticationStatus) | ||
.handshakeStatus(handshakeStatus) | ||
.connectionStatus(connectionStatus) | ||
.username(username) | ||
.tunneledBytes(tunneledBytes) | ||
.tunneledDestinationAddress(tunneledDestinationAddress) | ||
.tunneledDestinationHost(tunneledDestinationHost) | ||
.tunneledDestinationPort(tunneledDestinationPort) | ||
.establishedAt(establishedAt) | ||
.terminatedAt(terminatedAt) | ||
.mostRecentSegmentTime(mostRecentSegmentTime) | ||
.updatedAt(updatedAt) | ||
.createdAt(createdAt) | ||
.build(); | ||
} | ||
|
||
public static Builder builder() { | ||
return new AutoValue_SocksTunnelEntry.Builder(); | ||
} | ||
|
||
@AutoValue.Builder | ||
public abstract static class Builder { | ||
public abstract Builder id(long id); | ||
|
||
public abstract Builder uuid(UUID uuid); | ||
|
||
public abstract Builder tapUuid(UUID tapUuid); | ||
|
||
public abstract Builder tcpSessionKey(String tcpSessionKey); | ||
|
||
public abstract Builder socksType(String socksType); | ||
|
||
public abstract Builder authenticationStatus(String authenticationStatus); | ||
|
||
public abstract Builder handshakeStatus(String handshakeStatus); | ||
|
||
public abstract Builder connectionStatus(String connectionStatus); | ||
|
||
public abstract Builder username(String username); | ||
|
||
public abstract Builder tunneledBytes(int tunneledBytes); | ||
|
||
public abstract Builder tunneledDestinationAddress(String tunneledDestinationAddress); | ||
|
||
public abstract Builder tunneledDestinationHost(String tunneledDestinationHost); | ||
|
||
public abstract Builder tunneledDestinationPort(int tunneledDestinationPort); | ||
|
||
public abstract Builder establishedAt(DateTime establishedAt); | ||
|
||
public abstract Builder terminatedAt(DateTime terminatedAt); | ||
|
||
public abstract Builder mostRecentSegmentTime(DateTime mostRecentSegmentTime); | ||
|
||
public abstract Builder updatedAt(DateTime updatedAt); | ||
|
||
public abstract Builder createdAt(DateTime createdAt); | ||
|
||
public abstract SocksTunnelEntry build(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/app/nzyme/core/ethernet/socks/db/SocksTunnelEntryMapper.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,37 @@ | ||
package app.nzyme.core.ethernet.socks.db; | ||
|
||
import org.jdbi.v3.core.mapper.RowMapper; | ||
import org.jdbi.v3.core.statement.StatementContext; | ||
import org.joda.time.DateTime; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.util.UUID; | ||
|
||
public class SocksTunnelEntryMapper implements RowMapper<SocksTunnelEntry> { | ||
|
||
@Override | ||
public SocksTunnelEntry map(ResultSet rs, StatementContext ctx) throws SQLException { | ||
return SocksTunnelEntry.create( | ||
rs.getLong("id"), | ||
UUID.fromString(rs.getString("uuid")), | ||
UUID.fromString(rs.getString("tap_uuid")), | ||
rs.getString("tcp_session_key"), | ||
rs.getString("socks_type"), | ||
rs.getString("authentication_status"), | ||
rs.getString("handshake_status"), | ||
rs.getString("connection_status"), | ||
rs.getString("username"), | ||
rs.getInt("tunneled_bytes"), | ||
rs.getString("tunneled_destination_address"), | ||
rs.getString("tunneled_destination_host"), | ||
rs.getInt("tunneled_destination_port"), | ||
new DateTime(rs.getTimestamp("established_at")), | ||
new DateTime(rs.getTimestamp("terminated_at")), | ||
new DateTime(rs.getTimestamp("most_recent_segment_time")), | ||
new DateTime(rs.getTimestamp("updated_at")), | ||
new DateTime(rs.getTimestamp("created_at")) | ||
); | ||
} | ||
|
||
} |
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
Oops, something went wrong.