Skip to content

Commit

Permalink
DoHQueryStats -> DoHQuerySummary
Browse files Browse the repository at this point in the history
  • Loading branch information
jyyi1 committed Feb 21, 2024
1 parent 3b117e4 commit f95dd86
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
20 changes: 10 additions & 10 deletions Android/app/src/go/backend/doh.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ type DoHListener interface {
OnQuery(url string) DoHQueryToken

// OnResponse will be called when a DoH response has been received.
OnResponse(DoHQueryToken, *DoHQueryStats)
OnResponse(DoHQueryToken, *DoHQuerySumary)
}

// DoHStatus is an integer representing the status of a DoH transaction.
Expand All @@ -116,18 +116,18 @@ const (
DoHStatusInternalError DoHStatus = doh.InternalError // This should never happen
)

// DoHQueryStats is the summary of a DNS transaction.
// DoHQuerySumary is the summary of a DNS transaction.
// It will be reported to [DoHListener].OnResponse when it is complete.
type DoHQueryStats struct {
type DoHQuerySumary struct {
summ *doh.Summary
}

func (q DoHQueryStats) GetQuery() []byte { return q.summ.Query }
func (q DoHQueryStats) GetResponse() []byte { return q.summ.Response }
func (q DoHQueryStats) GetServer() string { return q.summ.Server }
func (q DoHQueryStats) GetStatus() DoHStatus { return q.summ.Status }
func (q DoHQueryStats) GetHTTPStatus() int { return q.summ.HTTPStatus }
func (q DoHQueryStats) GetLatency() float64 { return q.summ.Latency }
func (q DoHQuerySumary) GetQuery() []byte { return q.summ.Query }
func (q DoHQuerySumary) GetResponse() []byte { return q.summ.Response }
func (q DoHQuerySumary) GetServer() string { return q.summ.Server }
func (q DoHQuerySumary) GetStatus() DoHStatus { return q.summ.Status }
func (q DoHQuerySumary) GetHTTPStatus() int { return q.summ.HTTPStatus }
func (q DoHQuerySumary) GetLatency() float64 { return q.summ.Latency }

// dohListenerAdapter is an adapter for the internal [doh.Listener].
type dohListenerAdapter struct {
Expand All @@ -148,5 +148,5 @@ func (e dohListenerAdapter) OnQuery(url string) doh.Token {
}

func (e dohListenerAdapter) OnResponse(t doh.Token, s *doh.Summary) {
e.l.OnResponse(t, &DoHQueryStats{s})
e.l.OnResponse(t, &DoHQuerySumary{s})
}
24 changes: 12 additions & 12 deletions Android/app/src/main/java/app/intra/net/go/GoIntraListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import app.intra.sys.firebase.AnalyticsWrapper;
import backend.Backend;
import backend.DoHListener;
import backend.DoHQueryStats;
import backend.DoHQuerySumary;
import backend.DoHQueryToken;
import intra.TCPSocketSummary;
import intra.UDPSocketSummary;
Expand Down Expand Up @@ -125,30 +125,30 @@ private static int len(byte[] a) {
}

@Override
public void onResponse(DoHQueryToken token, DoHQueryStats stats) {
if (stats.getHTTPStatus() != 0 && token != null) {
public void onResponse(DoHQueryToken token, DoHQuerySumary summary) {
if (summary.getHTTPStatus() != 0 && token != null) {
// HTTP transaction completed. Report performance metrics.
Metric m = (Metric)token;
m.metric.setRequestPayloadSize(len(stats.getQuery()));
m.metric.setHttpResponseCode((int)stats.getHTTPStatus());
m.metric.setResponsePayloadSize(len(stats.getResponse()));
m.metric.setRequestPayloadSize(len(summary.getQuery()));
m.metric.setHttpResponseCode((int)summary.getHTTPStatus());
m.metric.setResponsePayloadSize(len(summary.getResponse()));
m.metric.stop(); // Finalizes the metric and queues it for upload.
}

final DnsPacket query;
try {
query = new DnsPacket(stats.getQuery());
query = new DnsPacket(summary.getQuery());
} catch (ProtocolException e) {
return;
}
long latencyMs = (long)(1000 * stats.getLatency());
long latencyMs = (long)(1000 * summary.getLatency());
long nowMs = SystemClock.elapsedRealtime();
long queryTimeMs = nowMs - latencyMs;
Transaction transaction = new Transaction(query, queryTimeMs);
transaction.response = stats.getResponse();
transaction.responseTime = (long)(1000 * stats.getLatency());
transaction.serverIp = stats.getServer();
transaction.status = goStatusMap.get(stats.getStatus());
transaction.response = summary.getResponse();
transaction.responseTime = (long)(1000 * summary.getLatency());
transaction.serverIp = summary.getServer();
transaction.status = goStatusMap.get(summary.getStatus());
transaction.responseCalendar = Calendar.getInstance();

vpnService.recordTransaction(transaction);
Expand Down

0 comments on commit f95dd86

Please sign in to comment.