Skip to content

Commit 3a23f7d

Browse files
committed
merge changes from master
2 parents dd5bf2b + a029d7f commit 3a23f7d

File tree

92 files changed

+5006
-5972
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+5006
-5972
lines changed

.github/workflows/golang.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ jobs:
6363
uses: golangci/golangci-lint-action@v3
6464
with:
6565
version: latest
66-
args: -v --disable structcheck,govet
66+
args: -v --disable structcheck,govet --timeout 5m

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11

22
backup/
3-
conjure
4-
application/application
3+
cmd/application/application
54
libtapdance/genkey
5+
libtapdance/*.o
6+
libtapdance/*.a
67
cmd/registration-server/registration-server
8+
cmd/registration-server/regserver
79
target
810
bin/
911
Cargo.lock

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ endif
8585

8686
clean:
8787
cargo clean
88-
rm -f ${TARGETS} *.o *~ ${EXE_DIR}
88+
$(RM) -rf *.o *~ ${EXE_DIR}
89+
cd ./libtapdance/ && make clean
8990

9091
${PROTO_RS_PATH}:
9192
cd ./proto/ && make

cmd/application/connectingStats.go

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"sync/atomic"
6+
7+
cj "github.com/refraction-networking/conjure/pkg/station/lib"
8+
)
9+
10+
var _ cj.ConnectingTpStats = &connStats{}
11+
12+
type connectingCounts struct {
13+
numCreatedConnecting int64
14+
numDialSuccessfulConnecting int64
15+
numListenSuccessfulConnecting int64
16+
numSuccessfulConnecting int64
17+
numTimeoutConnecting int64
18+
numAuthFailConnecting int64
19+
numOtherFailConnecting int64
20+
}
21+
22+
func (c *connStats) AddCreatedConnecting(asn uint, cc string, tp string) {
23+
atomic.AddInt64(&c.numCreatedConnecting, 1)
24+
25+
if isValidCC(cc) {
26+
c.m.Lock()
27+
defer c.m.Unlock()
28+
if _, ok := c.v4geoIPMap[asn]; !ok {
29+
// We haven't seen asn before, so add it to the map
30+
c.v4geoIPMap[asn] = &asnCounts{}
31+
c.v4geoIPMap[asn].cc = cc
32+
}
33+
atomic.AddInt64(&c.v4geoIPMap[asn].numCreatedConnecting, 1)
34+
}
35+
}
36+
37+
func (c *connStats) AddCreatedToListenSuccessfulConnecting(asn uint, cc string, tp string) {
38+
atomic.AddInt64(&c.numCreatedConnecting, -1)
39+
atomic.AddInt64(&c.numListenSuccessfulConnecting, 1)
40+
41+
if isValidCC(cc) {
42+
c.m.Lock()
43+
defer c.m.Unlock()
44+
if _, ok := c.v4geoIPMap[asn]; !ok {
45+
// We haven't seen asn before, so add it to the map
46+
c.v4geoIPMap[asn] = &asnCounts{}
47+
c.v4geoIPMap[asn].cc = cc
48+
}
49+
atomic.AddInt64(&c.v4geoIPMap[asn].numCreatedConnecting, -1)
50+
atomic.AddInt64(&c.v4geoIPMap[asn].numListenSuccessfulConnecting, 1)
51+
}
52+
}
53+
54+
func (c *connStats) AddCreatedToDialSuccessfulConnecting(asn uint, cc string, tp string) {
55+
atomic.AddInt64(&c.numCreatedConnecting, -1)
56+
atomic.AddInt64(&c.numDialSuccessfulConnecting, 1)
57+
58+
if isValidCC(cc) {
59+
c.m.Lock()
60+
defer c.m.Unlock()
61+
if _, ok := c.v4geoIPMap[asn]; !ok {
62+
// We haven't seen asn before, so add it to the map
63+
c.v4geoIPMap[asn] = &asnCounts{}
64+
c.v4geoIPMap[asn].cc = cc
65+
}
66+
atomic.AddInt64(&c.v4geoIPMap[asn].numCreatedConnecting, -1)
67+
atomic.AddInt64(&c.v4geoIPMap[asn].numDialSuccessfulConnecting, 1)
68+
}
69+
}
70+
71+
func (c *connStats) AddCreatedToSuccessfulConnecting(asn uint, cc string, tp string) {
72+
atomic.AddInt64(&c.numCreatedConnecting, -1)
73+
atomic.AddInt64(&c.numSuccessfulConnecting, 1)
74+
75+
if isValidCC(cc) {
76+
c.m.Lock()
77+
defer c.m.Unlock()
78+
if _, ok := c.v4geoIPMap[asn]; !ok {
79+
// We haven't seen asn before, so add it to the map
80+
c.v4geoIPMap[asn] = &asnCounts{}
81+
c.v4geoIPMap[asn].cc = cc
82+
}
83+
atomic.AddInt64(&c.v4geoIPMap[asn].numCreatedConnecting, -1)
84+
atomic.AddInt64(&c.v4geoIPMap[asn].numSuccessfulConnecting, 1)
85+
}
86+
}
87+
88+
func (c *connStats) AddCreatedToTimeoutConnecting(asn uint, cc string, tp string) {
89+
atomic.AddInt64(&c.numCreatedConnecting, -1)
90+
atomic.AddInt64(&c.numTimeoutConnecting, 1)
91+
92+
if isValidCC(cc) {
93+
c.m.Lock()
94+
defer c.m.Unlock()
95+
if _, ok := c.v4geoIPMap[asn]; !ok {
96+
// We haven't seen asn before, so add it to the map
97+
c.v4geoIPMap[asn] = &asnCounts{}
98+
c.v4geoIPMap[asn].cc = cc
99+
}
100+
atomic.AddInt64(&c.v4geoIPMap[asn].numCreatedConnecting, -1)
101+
atomic.AddInt64(&c.v4geoIPMap[asn].numTimeoutConnecting, 1)
102+
}
103+
}
104+
105+
func (c *connStats) AddSuccessfulToDiscardedConnecting(asn uint, cc string, tp string) {
106+
}
107+
108+
func (c *connStats) AddAuthFailConnecting(asn uint, cc string, tp string) {
109+
atomic.AddInt64(&c.numAuthFailConnecting, 1)
110+
111+
if isValidCC(cc) {
112+
c.m.Lock()
113+
defer c.m.Unlock()
114+
if _, ok := c.v4geoIPMap[asn]; !ok {
115+
// We haven't seen asn before, so add it to the map
116+
c.v4geoIPMap[asn] = &asnCounts{}
117+
c.v4geoIPMap[asn].cc = cc
118+
}
119+
atomic.AddInt64(&c.v4geoIPMap[asn].numAuthFailConnecting, 1)
120+
}
121+
122+
}
123+
124+
func (c *connStats) AddOtherFailConnecting(asn uint, cc string, tp string) {
125+
atomic.AddInt64(&c.numOtherFailConnecting, 1)
126+
127+
if isValidCC(cc) {
128+
c.m.Lock()
129+
defer c.m.Unlock()
130+
if _, ok := c.v4geoIPMap[asn]; !ok {
131+
// We haven't seen asn before, so add it to the map
132+
c.v4geoIPMap[asn] = &asnCounts{}
133+
c.v4geoIPMap[asn].cc = cc
134+
}
135+
atomic.AddInt64(&c.v4geoIPMap[asn].numOtherFailConnecting, 1)
136+
}
137+
138+
}
139+
140+
func (c *connStats) resetConnecting() {
141+
c.connectingCounts = connectingCounts{}
142+
}
143+
144+
func (c *connectingCounts) string() string {
145+
totalEndStates := atomic.LoadInt64(&c.numDialSuccessfulConnecting) + atomic.LoadInt64(&c.numListenSuccessfulConnecting) + atomic.LoadInt64(&c.numTimeoutConnecting) + atomic.LoadInt64(&c.numAuthFailConnecting) + atomic.LoadInt64(&c.numOtherFailConnecting)
146+
if totalEndStates < 1 {
147+
totalEndStates = 0
148+
}
149+
return fmt.Sprintf("%d %d %d %d %d %d %d",
150+
atomic.LoadInt64(&c.numCreatedConnecting),
151+
atomic.LoadInt64(&c.numDialSuccessfulConnecting),
152+
atomic.LoadInt64(&c.numListenSuccessfulConnecting),
153+
atomic.LoadInt64(&c.numTimeoutConnecting),
154+
atomic.LoadInt64(&c.numAuthFailConnecting),
155+
atomic.LoadInt64(&c.numOtherFailConnecting),
156+
totalEndStates,
157+
)
158+
}

cmd/application/conns.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ readLoop:
315315

316316
transports:
317317
for i, t := range possibleTransports {
318-
reg, wrapped, err = t.WrapConnection(&received, clientConn, originalDstIP, regManager)
318+
wrappedReg, wrappedConn, err := t.WrapConnection(&received, clientConn, originalDstIP, regManager)
319+
319320
err = generalizeErr(err)
320321
if errors.Is(err, transports.ErrTryAgain) {
321322
continue transports
@@ -335,6 +336,16 @@ readLoop:
335336
return
336337
}
337338

339+
ok := false
340+
reg, ok = wrappedReg.(*cj.DecoyRegistration)
341+
if !ok {
342+
logger.Errorf("unexpected returned reg type from transport: %T, expected: %T", wrapped, reg)
343+
delete(possibleTransports, i)
344+
continue transports
345+
}
346+
// set outer wrapped var
347+
wrapped = wrappedConn
348+
338349
// We found our transport! First order of business: disable deadline
339350
err = wrapped.SetDeadline(time.Time{})
340351
if err != nil {
@@ -404,6 +415,8 @@ type statCounts struct {
404415
totalTransitions int64 // Number of all transitions tracked
405416
numNewConns int64 // Number new connections potentially handshaking
406417
numResolved int64 // Number connections that have reached a terminal state.
418+
419+
connectingCounts
407420
}
408421

409422
type asnCounts struct {
@@ -418,6 +431,8 @@ type connStats struct {
418431
ipv6 statCounts
419432
v4geoIPMap map[uint]*asnCounts
420433
v6geoIPMap map[uint]*asnCounts
434+
435+
connectingCounts
421436
}
422437

423438
func (c *connStats) PrintAndReset(logger *log.Logger) {
@@ -433,7 +448,7 @@ func (c *connStats) PrintAndReset(logger *log.Logger) {
433448
}
434449

435450
if numASNs > 0 {
436-
logger.Infof("conn-stats (IPv4): %d %d %d %d %d %.3f %d %.3f %d %.3f %d %.3f %d %.3f %d",
451+
logger.Infof("conn-stats (IPv4): %d %d %d %d %d %.3f %d %.3f %d %.3f %d %.3f %d %.3f %d %s",
437452
atomic.LoadInt64(&c.ipv4.numCreated),
438453
atomic.LoadInt64(&c.ipv4.numReading),
439454
atomic.LoadInt64(&c.ipv4.numChecking),
@@ -449,6 +464,7 @@ func (c *connStats) PrintAndReset(logger *log.Logger) {
449464
atomic.LoadInt64(&c.ipv4.numClosed),
450465
1000*float64(atomic.LoadInt64(&c.ipv4.numClosed))/epochDur,
451466
numASNs,
467+
c.connectingCounts.string(),
452468
)
453469
}
454470

@@ -484,7 +500,7 @@ func (c *connStats) PrintAndReset(logger *log.Logger) {
484500
}
485501
for asn, counts := range val {
486502
var tt = math.Max(1, float64(atomic.LoadInt64(&counts.totalTransitions)))
487-
logger.Infof("conn-stats-verbose (IPv%d): %d %s %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %d %d %d %d",
503+
logger.Infof("conn-stats-verbose (IPv%d): %d %s %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %d %d %d %d %s",
488504
ip_ver,
489505
asn,
490506
counts.cc,
@@ -530,6 +546,7 @@ func (c *connStats) PrintAndReset(logger *log.Logger) {
530546
atomic.LoadInt64(&counts.numNewConns),
531547
atomic.LoadInt64(&c.ipv6.numResolved),
532548
atomic.LoadInt64(&counts.numResolved),
549+
counts.connectingCounts.string(),
533550
)
534551
}
535552
}
@@ -602,6 +619,8 @@ func (c *connStats) reset() {
602619
c.v6geoIPMap = make(map[uint]*asnCounts)
603620

604621
c.epochStart = time.Now()
622+
623+
c.resetConnecting()
605624
}
606625

607626
func (c *connStats) addCreated(asn uint, cc string, isIPv4 bool) {

cmd/application/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/refraction-networking/conjure/cmd/application
2+
3+
go 1.20

cmd/application/go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
github.com/refraction-networking/conjure v0.6.0-dtlsbeta h1:4k0Y93MR6sgLQUs2nFyUZO0pdSx5JWDPjFq/EpuVsnQ=
2+
github.com/refraction-networking/conjure v0.6.0-dtlsbeta/go.mod h1:/Ah4d0Pa8tIjKHaZhA/50l0E+IehYmzewSg46SfG7hw=
3+
github.com/refraction-networking/conjure v0.6.0 h1:kDOWPE9WY+zquJsXDifxjUh98LlqJB+fhlEyoqQdlug=
4+
github.com/refraction-networking/conjure v0.6.0/go.mod h1:iRRZEI3nZsBLn1Er6xPwGwi68XNCKlno4kkWlMvMSk8=

cmd/application/main.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55
"flag"
6+
"net"
67
"os"
78
"os/signal"
89
"strconv"
@@ -12,6 +13,7 @@ import (
1213

1314
cj "github.com/refraction-networking/conjure/pkg/station/lib"
1415
"github.com/refraction-networking/conjure/pkg/station/log"
16+
"github.com/refraction-networking/conjure/pkg/transports/connecting/dtls"
1517
"github.com/refraction-networking/conjure/pkg/transports/wrapping/min"
1618
"github.com/refraction-networking/conjure/pkg/transports/wrapping/obfs4"
1719
"github.com/refraction-networking/conjure/pkg/transports/wrapping/prefix"
@@ -53,7 +55,38 @@ func main() {
5355
}
5456
log.SetLevel(logLevel)
5557

58+
connManager := newConnManager(nil)
59+
60+
conf.RegConfig.ConnectingStats = connManager
61+
5662
regManager := cj.NewRegistrationManager(conf.RegConfig)
63+
64+
logIPDTLS := func(logger func(asn uint, cc, tp string)) func(*net.IP) {
65+
return func(ip *net.IP) {
66+
cc, err := regManager.GeoIP.CC(*ip)
67+
if err != nil {
68+
return
69+
}
70+
71+
var asn uint = 0
72+
if cc != "unk" {
73+
asn, err = regManager.GeoIP.ASN(*ip)
74+
if err != nil {
75+
return
76+
}
77+
}
78+
79+
logger(asn, cc, "dtls")
80+
}
81+
}
82+
83+
dtlsTransport, err := dtls.NewTransport(logIPDTLS(connManager.AddAuthFailConnecting), logIPDTLS(connManager.AddOtherFailConnecting), logIPDTLS(connManager.AddCreatedToDialSuccessfulConnecting), logIPDTLS(connManager.AddCreatedToListenSuccessfulConnecting))
84+
85+
if err != nil {
86+
log.Fatalf("failed to setup dtls: %v", err)
87+
}
88+
enabledTransports[pb.TransportType_DTLS] = dtlsTransport
89+
5790
sharedLogger = regManager.Logger
5891
logger := sharedLogger
5992
defer regManager.Cleanup()
@@ -98,8 +131,6 @@ func main() {
98131
logger.Fatal("error creating ZMQ Ingest: %w", err)
99132
}
100133

101-
connManager := newConnManager(nil)
102-
103134
cj.Stat().AddStatsModule(zmqIngester, false)
104135
cj.Stat().AddStatsModule(regManager.LivenessTester, false)
105136
cj.Stat().AddStatsModule(cj.GetProxyStats(), false)

cmd/application/registration_with_transport_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ func TestManagerFunctionality(t *testing.T) {
6464
storedReg := potentialRegistrations[string(core.ConjureHMAC(newReg.Keys.SharedSecret, "MinTrasportHMACString"))]
6565
require.NotNil(t, storedReg)
6666

67-
if storedReg.PhantomIp.String() != "192.122.190.148" || storedReg.Covert != "52.44.73.6:443" {
68-
t.Fatalf("Improper registration returned: %v\n", storedReg.String())
67+
reg := storedReg.(*cj.DecoyRegistration)
68+
69+
if reg.PhantomIp.String() != "192.122.190.148" || reg.Covert != "52.44.73.6:443" {
70+
t.Fatalf("Improper registration returned: %v\n", reg.String())
6971
}
7072
}
7173

0 commit comments

Comments
 (0)