Skip to content

Commit 9e45ac7

Browse files
committed
Don't export internal structures to outside world - gomobile picks them up
1 parent 5c29aef commit 9e45ac7

8 files changed

+39
-39
lines changed

gomobile_ios.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env bash
2-
#Only works with patched gomobile version
2+
33
CGO_LDFLAGS_ALLOW="-fobjc-arc" \
44
gomobile bind -target=ios/arm64 $@ -iosversion=10.3 -v github.com/mysteriumnetwork/go-openvpn/openvpn3

openvpn3/c_args.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,39 @@ package openvpn3
44
import "C"
55
import "unsafe"
66

7-
type CCharPointer struct {
7+
type cCharPointer struct {
88
Ptr *C.char
99
}
1010

11-
func NewCharPointer(str string) *CCharPointer {
12-
return &CCharPointer{
11+
func newCharPointer(str string) *cCharPointer {
12+
return &cCharPointer{
1313
Ptr: C.CString(str),
1414
}
1515
}
1616

17-
func (ptr *CCharPointer) Delete() {
17+
func (ptr *cCharPointer) delete() {
1818
C.free(unsafe.Pointer(ptr.Ptr))
1919
}
2020

21-
type CCharPointerArray struct {
21+
type cCharPointerArray struct {
2222
pointers []*C.char
2323
}
2424

25-
func (a *CCharPointerArray) AddAll(args ...string) {
25+
func (a *cCharPointerArray) addAll(args ...string) {
2626
for _, arg := range args {
2727
a.pointers = append(a.pointers, C.CString(arg))
2828
}
2929
}
3030

31-
func (a *CCharPointerArray) cPointer() **C.char {
31+
func (a *cCharPointerArray) cPointer() **C.char {
3232
return (**C.char)(&a.pointers[0])
3333
}
3434

35-
func (a *CCharPointerArray) cCount() C.int {
35+
func (a *cCharPointerArray) cCount() C.int {
3636
return C.int(len(a.pointers))
3737
}
3838

39-
func (a *CCharPointerArray) Free() {
39+
func (a *cCharPointerArray) free() {
4040
for _, arg := range a.pointers {
4141
C.free(unsafe.Pointer(arg))
4242
}

openvpn3/callback_bridge.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ extern void goEventCallback(user_callback_data usrData, conn_event event);
1414
*/
1515
import "C"
1616

17-
var callbacks = NewCallbackRegistry()
17+
var callbacks = newCallbackRegistry()
1818

1919
//export goStatsCallback
2020
func goStatsCallback(ptr C.user_callback_data, cStats C.conn_stats) {
2121
id := int(ptr)
2222
var stats Statistics
2323
stats.BytesIn = int(cStats.bytes_in)
2424
stats.BytesOut = int(cStats.bytes_out)
25-
callbacks.Stats(id, stats)
25+
callbacks.stats(id, stats)
2626
}
2727

2828
//export goLogCallback
2929
func goLogCallback(ptr C.user_callback_data, cStr *C.char) {
3030
goStr := C.GoString(cStr)
3131
id := int(ptr)
32-
callbacks.Log(id, goStr)
32+
callbacks.log(id, goStr)
3333
}
3434

3535
//export goEventCallback
@@ -40,7 +40,7 @@ func goEventCallback(ptr C.user_callback_data, cEvent C.conn_event) {
4040
e.Fatal = bool(cEvent.fatal)
4141
e.Name = C.GoString(cEvent.name)
4242
e.Info = C.GoString(cEvent.info)
43-
callbacks.Event(id, e)
43+
callbacks.event(id, e)
4444
}
4545

4646
func SelfCheck(logger Logger) {

openvpn3/callback_registry.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ type StatsConsumer interface {
2626
OnStats(*Statistics)
2727
}
2828

29-
type Unregister func()
29+
type unregister func()
3030

31-
type CallbackRegistry struct {
31+
type callbackRegistry struct {
3232
lock sync.Locker
3333
idMap map[int]interface{}
3434
lastId int
3535
}
3636

37-
func (cr *CallbackRegistry) register(callbacks interface{}) (int, Unregister) {
37+
func (cr *callbackRegistry) register(callbacks interface{}) (int, unregister) {
3838
cr.lock.Lock()
3939
defer cr.lock.Unlock()
4040

@@ -48,13 +48,13 @@ func (cr *CallbackRegistry) register(callbacks interface{}) (int, Unregister) {
4848
}
4949
}
5050

51-
func (cr *CallbackRegistry) unregister(id int) {
51+
func (cr *callbackRegistry) unregister(id int) {
5252
cr.lock.Lock()
5353
defer cr.lock.Unlock()
5454
delete(cr.idMap, id)
5555
}
5656

57-
func (cr *CallbackRegistry) Log(id int, text string) {
57+
func (cr *callbackRegistry) log(id int, text string) {
5858
cr.lock.Lock()
5959
defer cr.lock.Unlock()
6060
callback, ok := cr.idMap[id]
@@ -68,7 +68,7 @@ func (cr *CallbackRegistry) Log(id int, text string) {
6868
logCallback.Log(text)
6969
}
7070

71-
func (cr *CallbackRegistry) Event(id int, event Event) {
71+
func (cr *callbackRegistry) event(id int, event Event) {
7272
cr.lock.Lock()
7373
defer cr.lock.Unlock()
7474
callback, ok := cr.idMap[id]
@@ -83,7 +83,7 @@ func (cr *CallbackRegistry) Event(id int, event Event) {
8383

8484
}
8585

86-
func (cr *CallbackRegistry) Stats(id int, stats Statistics) {
86+
func (cr *callbackRegistry) stats(id int, stats Statistics) {
8787
cr.lock.Lock()
8888
defer cr.lock.Unlock()
8989
callback, ok := cr.idMap[id]
@@ -98,8 +98,8 @@ func (cr *CallbackRegistry) Stats(id int, stats Statistics) {
9898

9999
}
100100

101-
func NewCallbackRegistry() *CallbackRegistry {
102-
return &CallbackRegistry{
101+
func newCallbackRegistry() *callbackRegistry {
102+
return &callbackRegistry{
103103
lastId: 0,
104104
idMap: make(map[int]interface{}),
105105
lock: &sync.Mutex{},

openvpn3/callback_registry_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
)
77

88
func TestTwoCallbacksAreAdded(t *testing.T) {
9-
registry := NewCallbackRegistry()
9+
registry := newCallbackRegistry()
1010

1111
id1, _ := registry.register("abc")
1212
id2, _ := registry.register("def")
@@ -16,7 +16,7 @@ func TestTwoCallbacksAreAdded(t *testing.T) {
1616
}
1717

1818
func TestCallbackRemovedOnUnregister(t *testing.T) {
19-
registry := NewCallbackRegistry()
19+
registry := newCallbackRegistry()
2020
id, unregister := registry.register("abc")
2121

2222
assert.Contains(t, registry.idMap, id)
@@ -25,32 +25,32 @@ func TestCallbackRemovedOnUnregister(t *testing.T) {
2525
}
2626

2727
func TestLogCallbackCalled(t *testing.T) {
28-
registry := NewCallbackRegistry()
28+
registry := newCallbackRegistry()
2929

3030
callback := &mockedCallback{}
3131
id, _ := registry.register(callback)
3232

33-
registry.Log(id, "test")
33+
registry.log(id, "test")
3434

3535
assert.True(t, callback.logCalled)
3636
}
3737

3838
func TestEventCallbackCalled(t *testing.T) {
39-
registry := NewCallbackRegistry()
39+
registry := newCallbackRegistry()
4040
callback := &mockedCallback{}
4141

4242
id, _ := registry.register(callback)
43-
registry.Event(id, Event{})
43+
registry.event(id, Event{})
4444

4545
assert.True(t, callback.eventCalled)
4646
}
4747

4848
func TestStatsCallbackCalled(t *testing.T) {
49-
registry := NewCallbackRegistry()
49+
registry := newCallbackRegistry()
5050
callback := &mockedCallback{}
5151

5252
id, _ := registry.register(callback)
53-
registry.Stats(id, Statistics{})
53+
registry.stats(id, Statistics{})
5454

5555
assert.True(t, callback.statsCalled)
5656
}

openvpn3/session.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ func (session *Session) Start(profile string, creds *Credentials) {
5454
go func() {
5555
defer session.finished.Done()
5656

57-
profileContent := NewCharPointer(profile)
58-
defer profileContent.Delete()
57+
profileContent := newCharPointer(profile)
58+
defer profileContent.delete()
5959

60-
cUsername := NewCharPointer(creds.Username)
61-
defer cUsername.Delete()
60+
cUsername := newCharPointer(creds.Username)
61+
defer cUsername.delete()
6262

63-
cPassword := NewCharPointer(creds.Password)
64-
defer cPassword.Delete()
63+
cPassword := newCharPointer(creds.Password)
64+
defer cPassword.delete()
6565

6666
cCreds := expCredentials{
6767
username: cUsername.Ptr,

openvpn3/tun_setup_bridge.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ var tunnelSetupRegistry = tunSetupRegistry{
262262
}
263263

264264
func registerTunnelSetupDelegate(delegate TunnelSetup) (C.tun_builder_callbacks, func()) {
265-
id, unregister := tunnelSetupRegistry.Register(delegate)
265+
id, unregister := tunnelSetupRegistry.register(delegate)
266266
return C.tun_builder_callbacks{
267267
usrData: C.user_callback_data(id),
268268
//delegates to go callbacks

openvpn3/tun_setup_registry.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type tunSetupRegistry struct {
88
lastId int
99
}
1010

11-
func (registry *tunSetupRegistry) Register(delegate TunnelSetup) (int, func()) {
11+
func (registry *tunSetupRegistry) register(delegate TunnelSetup) (int, func()) {
1212
registry.lock.Lock()
1313
defer registry.lock.Unlock()
1414

0 commit comments

Comments
 (0)