Skip to content

Commit 4bd6d06

Browse files
authored
Merge pull request #80 from strykeforce/ipaddresses
Redo Link config for better client IP address checks
2 parents 09d791e + 702e44d commit 4bd6d06

File tree

12 files changed

+648
-427
lines changed

12 files changed

+648
-427
lines changed

admin/deadeye/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "21.2.0" # updated by scripts/bump.py
1+
__version__ = "21.3.0" # updated by scripts/bump.py

admin/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ authors = ["Jeff Hutchison <[email protected]>"]
33
description = "Deadeye admin console back-end"
44
license = "MIT"
55
name = "deadeye"
6-
version = "21.2.0" # updated by scripts/bump.py
6+
version = "21.3.0" # updated by scripts/bump.py
77

88
[tool.poetry.scripts]
99
deadeye = "deadeye.scripts.cli:main"

ansible/roles/deadeye/vars/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
deadeye_version: 21.2.0 # updated by scripts/bump.py
2+
deadeye_version: 21.3.0 # updated by scripts/bump.py
33
deadeye_repo: https://github.com/strykeforce/deadeye.git
44
deadeye_src: /opt/deadeye/src
55
deadeye_conf_dir: /etc/opt/deadeye

client/build.gradle.kts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
11
plugins {
2-
`idea`
2+
idea
33
`java-library`
44
`maven-publish`
55
}
66

77
group = "org.strykeforce"
8-
version = "21.2.0" // updated by scripts/bump.py
8+
version = "21.3.0" // updated by scripts/bump.py
99

1010
repositories {
1111
jcenter()
1212
maven(url = "https://frcmaven.wpi.edu/artifactory/release/")
13+
mavenCentral()
1314
}
1415

1516
dependencies {
1617
val wpiVersion = "2021.3.1"
17-
val slf4jVersion = "1.7.30"
18-
val junitVersion = "5.7.2"
18+
val slf4jVersion = "1.7.32"
19+
val junitVersion = "5.8.1"
1920
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
20-
implementation("com.squareup.moshi:moshi:1.11.0")
21+
implementation("com.squareup.moshi:moshi:1.12.0")
2122
implementation("edu.wpi.first.ntcore:ntcore-java:$wpiVersion")
2223
implementation("org.slf4j:slf4j-api:$slf4jVersion")
23-
implementation("org.jetbrains:annotations:20.1.0")
24+
implementation("org.jetbrains:annotations:22.0.0")
2425

2526

2627
// Use JUnit Jupiter API for testing.
2728
testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion")
29+
testImplementation("org.junit.jupiter:junit-jupiter-params:$junitVersion")
2830

2931
// Use JUnit Jupiter Engine for testing.
3032
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitVersion")
3133
testRuntimeOnly("edu.wpi.first.ntcore:ntcore-jni:$wpiVersion:osxx86-64")
3234
testRuntimeOnly("edu.wpi.first.wpiutil:wpiutil-java:$wpiVersion")
33-
testRuntimeOnly("org.slf4j:slf4j-nop:$slf4jVersion")
35+
testRuntimeOnly("ch.qos.logback:logback-classic:1.2.6")
3436
}
3537

3638
java {

client/src/main/java/org/strykeforce/deadeye/Deadeye.java

Lines changed: 66 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44
import com.squareup.moshi.Moshi;
55
import edu.wpi.first.networktables.NetworkTable;
66
import edu.wpi.first.networktables.NetworkTableInstance;
7-
import okio.BufferedSource;
8-
import org.jetbrains.annotations.NotNull;
9-
import org.jetbrains.annotations.Nullable;
10-
import org.slf4j.Logger;
11-
import org.slf4j.LoggerFactory;
12-
137
import java.io.IOException;
148
import java.lang.reflect.Constructor;
159
import java.lang.reflect.InvocationTargetException;
1610
import java.util.Objects;
1711
import java.util.regex.Pattern;
12+
import okio.BufferedSource;
13+
import org.jetbrains.annotations.NotNull;
14+
import org.jetbrains.annotations.Nullable;
15+
import org.slf4j.Logger;
16+
import org.slf4j.LoggerFactory;
1817

1918
/**
2019
* Represents a connection to a Deadeye camera. It provides methods to configure and control the
@@ -34,30 +33,58 @@ public class Deadeye<T extends TargetData> {
3433
/**
3534
* Initialize a connection to a Deadeye camera.
3635
*
37-
* @param id the camera id.
36+
* @param id the camera id.
3837
* @param cls the appropriate TargetData (or subclass) class object
3938
*/
4039
public Deadeye(String id, Class<T> cls) {
41-
this(id, cls, NetworkTableInstance.getDefault());
40+
this(id, cls, NetworkTableInstance.getDefault(), null);
41+
}
42+
43+
/**
44+
* Initialize a connection to a Deadeye camera and override the detected client IP address.
45+
*
46+
* @param id the camera id.
47+
* @param cls the appropriate TargetData (or subclass) class object
48+
* @param linkAddress override IP address to send client data to
49+
*/
50+
public Deadeye(String id, Class<T> cls, @Nullable String linkAddress) {
51+
this(id, cls, NetworkTableInstance.getDefault(), linkAddress);
4252
}
4353

54+
4455
/**
4556
* Initialize a connection to a Deadeye camera using a specified NetworkTables instance. This is
4657
* primarily used for testing.
4758
*
48-
* @param id the camera id.
59+
* @param id the camera id.
4960
* @param cls the appropriate TargetData (or subclass) class object
5061
* @param nti the NetworkTables instance to connect through
5162
*/
52-
@SuppressWarnings("unchecked")
5363
public Deadeye(String id, Class<T> cls, NetworkTableInstance nti) {
64+
this(id, cls, nti, null);
65+
}
66+
67+
/**
68+
* Initialize a connection to a Deadeye camera using a specified NetworkTables instance and
69+
* override the client IP address. This is primarily used for testing.
70+
*
71+
* @param id the camera id.
72+
* @param cls the appropriate TargetData (or subclass) class object
73+
* @param nti the NetworkTables instance to connect through
74+
* @param linkAddress override IP address to send target data to
75+
*/
76+
@SuppressWarnings("unchecked")
77+
public Deadeye(@NotNull String id, @NotNull Class<T> cls, @NotNull NetworkTableInstance nti,
78+
@Nullable String linkAddress) {
5479
if (!Pattern.matches("^[A-Za-z][0-4]$", id)) {
5580
throw new IllegalArgumentException(id);
5681
}
5782

5883
if (link == null) {
5984
synchronized (Link.class) {
60-
if (link == null) link = new Link(nti);
85+
if (link == null) {
86+
link = new Link(nti, linkAddress);
87+
}
6188
}
6289
}
6390

@@ -70,7 +97,9 @@ public Deadeye(String id, Class<T> cls, NetworkTableInstance nti) {
7097

7198
if (!link.isAlive()) {
7299
synchronized (Link.class) {
73-
if (!link.isAlive()) link.start();
100+
if (!link.isAlive()) {
101+
link.start();
102+
}
74103
}
75104
}
76105

@@ -87,6 +116,11 @@ public Deadeye(String id, Class<T> cls, NetworkTableInstance nti) {
87116
}
88117
}
89118

119+
static JsonAdapter<Info> getInfoJsonAdapter() {
120+
Moshi moshi = new Moshi.Builder().build();
121+
return moshi.adapter(Info.class);
122+
}
123+
90124
/**
91125
* Get TargetDataListener.
92126
*
@@ -107,7 +141,9 @@ public void setTargetDataListener(TargetDataListener<T> targetDataListener) {
107141

108142
public void handleTargetData(BufferedSource source) throws IOException {
109143
targetData = jsonAdapter.fromJson(source);
110-
if (targetDataListener != null) targetDataListener.onTargetData(targetData);
144+
if (targetDataListener != null) {
145+
targetDataListener.onTargetData(targetData);
146+
}
111147
}
112148

113149
/**
@@ -135,8 +171,11 @@ public boolean getEnabled() {
135171
* @param enabled true to turn camera on.
136172
*/
137173
public void setEnabled(boolean enabled) {
138-
if (enabled) table.getEntry("On").setBoolean(true);
139-
else table.getEntry("Off").setBoolean(true);
174+
if (enabled) {
175+
table.getEntry("On").setBoolean(true);
176+
} else {
177+
table.getEntry("Off").setBoolean(true);
178+
}
140179
}
141180

142181
/**
@@ -157,8 +196,11 @@ public boolean getLightEnabled() {
157196
*/
158197
public void setLightEnabled(boolean enabled) {
159198
NetworkTable light = table.getSubTable("Light");
160-
if (enabled) light.getEntry("On").setBoolean(true);
161-
else light.getEntry("Off").setBoolean(true);
199+
if (enabled) {
200+
light.getEntry("On").setBoolean(true);
201+
} else {
202+
light.getEntry("Off").setBoolean(true);
203+
}
162204
}
163205

164206
/**
@@ -189,16 +231,12 @@ public Info getInfo() {
189231
return info;
190232
}
191233

192-
static JsonAdapter<Info> getInfoJsonAdapter() {
193-
Moshi moshi = new Moshi.Builder().build();
194-
return moshi.adapter(Info.class);
195-
}
196-
197234
Link getLink() {
198235
return link;
199236
}
200237

201238
static class Info {
239+
202240
private final boolean logging;
203241
private final String pipeline;
204242
private final String version;
@@ -211,8 +249,12 @@ public Info(boolean logging, String pipeline, String version) {
211249

212250
@Override
213251
public boolean equals(Object o) {
214-
if (this == o) return true;
215-
if (o == null || getClass() != o.getClass()) return false;
252+
if (this == o) {
253+
return true;
254+
}
255+
if (o == null || getClass() != o.getClass()) {
256+
return false;
257+
}
216258
Info info = (Info) o;
217259
return logging == info.logging
218260
&& pipeline.equals(info.pipeline)

0 commit comments

Comments
 (0)