Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
bitmask-vpn
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
leap
bitmask-vpn
Commits
2439d744
Verified
Commit
2439d744
authored
6 years ago
by
meskio
Browse files
Options
Downloads
Patches
Plain Diff
[feat] sort gateways by timezone
And let us select gateways. - Resolves:
#42
parent
37413f5e
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!17
WIP: [feat] pure go bitmask vpn implemenation
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
bitmask_go/bonafide.go
+57
-3
57 additions, 3 deletions
bitmask_go/bonafide.go
bitmask_go/vpn.go
+10
-3
10 additions, 3 deletions
bitmask_go/vpn.go
config.go
+1
-8
1 addition, 8 deletions
config.go
main.go
+4
-3
4 additions, 3 deletions
main.go
systray.go
+1
-1
1 addition, 1 deletion
systray.go
with
73 additions
and
18 deletions
bitmask_go/bonafide.go
+
57
−
3
View file @
2439d744
...
...
@@ -23,6 +23,9 @@ import (
"io/ioutil"
"log"
"net/http"
"sort"
"strconv"
"time"
)
const
(
...
...
@@ -66,8 +69,9 @@ UN9SaWRlWKSdP4haujnzCoJbM7dU9bjvlGZNyXEekgeT0W2qFeGGp+yyUWw8tNsp
)
type
bonafide
struct
{
client
*
http
.
Client
eip
*
eipService
client
*
http
.
Client
eip
*
eipService
defaultGateway
string
}
type
eipService
struct
{
...
...
@@ -102,7 +106,7 @@ func newBonafide() *bonafide {
},
}
return
&
bonafide
{
client
,
nil
}
return
&
bonafide
{
client
,
nil
,
""
}
}
func
(
b
*
bonafide
)
getCertPem
()
([]
byte
,
error
)
{
...
...
@@ -129,6 +133,11 @@ func (b *bonafide) getGateways() ([]gateway, error) {
return
b
.
eip
.
Gateways
,
nil
}
func
(
b
*
bonafide
)
setDefaultGateway
(
name
string
)
{
b
.
defaultGateway
=
name
b
.
sortGateways
()
}
func
(
b
*
bonafide
)
getOpenvpnArgs
()
([]
string
,
error
)
{
if
b
.
eip
==
nil
{
err
:=
b
.
fetchEipJSON
()
...
...
@@ -171,5 +180,50 @@ func (b *bonafide) fetchEipJSON() error {
}
b
.
eip
=
&
eip
b
.
sortGateways
()
return
nil
}
func
(
b
*
bonafide
)
sortGateways
()
{
type
gatewayDistance
struct
{
gateway
gateway
distance
int
}
gws
:=
[]
gatewayDistance
{}
_
,
tzOffset
:=
time
.
Now
()
.
Zone
()
for
_
,
gw
:=
range
b
.
eip
.
Gateways
{
distance
:=
13
if
gw
.
Location
==
b
.
defaultGateway
{
distance
=
-
1
}
else
{
gwOffset
,
err
:=
strconv
.
Atoi
(
b
.
eip
.
Locations
[
gw
.
Location
]
.
Timezone
)
if
err
!=
nil
{
log
.
Printf
(
"Error sorting gateways: %v"
,
err
)
}
else
{
distance
=
tzDistance
(
tzOffset
,
gwOffset
)
}
}
gws
=
append
(
gws
,
gatewayDistance
{
gw
,
distance
})
}
sort
.
Slice
(
gws
,
func
(
i
,
j
int
)
bool
{
return
gws
[
i
]
.
distance
>
gws
[
j
]
.
distance
})
for
i
,
gw
:=
range
gws
{
b
.
eip
.
Gateways
[
i
]
=
gw
.
gateway
}
}
func
tzDistance
(
offset1
,
offset2
int
)
int
{
abs
:=
func
(
x
int
)
int
{
if
x
<
0
{
return
-
x
}
else
{
return
x
}
}
distance
:=
abs
(
offset1
-
offset2
)
if
distance
>
12
{
distance
=
24
-
distance
}
return
distance
}
This diff is collapsed.
Click to expand it.
bitmask_go/vpn.go
+
10
−
3
View file @
2439d744
...
...
@@ -81,13 +81,20 @@ func (b *Bitmask) VPNCheck() (helpers bool, priviledge bool, err error) {
// ListGateways return the names of the gateways
func
(
b
*
Bitmask
)
ListGateways
(
provider
string
)
([]
string
,
error
)
{
// TODO
return
[]
string
{},
nil
gateways
,
err
:=
b
.
bonafide
.
getGateways
()
if
err
!=
nil
{
return
nil
,
err
}
gatewayNames
:=
make
([]
string
,
len
(
gateways
))
for
i
,
gw
:=
range
gateways
{
gatewayNames
[
i
]
=
gw
.
Location
}
return
gatewayNames
,
nil
}
// UseGateway selects name as the default gateway
func
(
b
*
Bitmask
)
UseGateway
(
name
string
)
error
{
// TODO
b
.
bonafide
.
setDefaultGateway
(
name
)
return
nil
}
...
...
This diff is collapsed.
Click to expand it.
config.go
+
1
−
8
View file @
2439d744
...
...
@@ -17,7 +17,6 @@ package main
import
(
"encoding/json"
"flag"
"os"
"path"
"time"
...
...
@@ -37,7 +36,7 @@ var (
type
systrayConfig
struct
{
LastNotification
time
.
Time
Donated
time
.
Time
Select
W
ateway
bool
Select
G
ateway
bool
UserStoppedVPN
bool
}
...
...
@@ -53,7 +52,6 @@ func parseConfig() *systrayConfig {
dec
:=
json
.
NewDecoder
(
f
)
err
=
dec
.
Decode
(
&
conf
)
conf
.
parseFlags
()
return
&
conf
}
...
...
@@ -62,11 +60,6 @@ func (c *systrayConfig) setUserStoppedVPN(vpnStopped bool) error {
return
c
.
save
()
}
func
(
c
*
systrayConfig
)
parseFlags
()
{
flag
.
BoolVar
(
&
c
.
SelectWateway
,
"select-gateway"
,
false
,
"Enable gateway selection"
)
flag
.
Parse
()
}
func
(
c
*
systrayConfig
)
hasDonated
()
bool
{
return
c
.
Donated
.
Add
(
oneMonth
)
.
After
(
time
.
Now
())
}
...
...
This diff is collapsed.
Click to expand it.
main.go
+
4
−
3
View file @
2439d744
...
...
@@ -40,6 +40,10 @@ func main() {
// locking the main thread into an OS thread fixes the problem
runtime
.
LockOSThread
()
conf
:=
parseConfig
()
initPrinter
()
flag
.
BoolVar
(
&
conf
.
SelectGateway
,
"select-gateway"
,
false
,
"Enable gateway selection"
)
versionFlag
:=
flag
.
Bool
(
"version"
,
false
,
"Version of the bitmask-systray"
)
flag
.
Parse
()
if
*
versionFlag
{
...
...
@@ -57,9 +61,6 @@ func main() {
}
defer
releasePID
()
conf
:=
parseConfig
()
initPrinter
()
notify
:=
newNotificator
(
conf
)
b
,
err
:=
initBitmask
()
...
...
This diff is collapsed.
Click to expand it.
systray.go
+
1
−
1
View file @
2439d744
...
...
@@ -77,7 +77,7 @@ func (bt *bmTray) onReady() {
bt
.
mCancel
.
Hide
()
systray
.
AddSeparator
()
if
bt
.
conf
.
Select
W
ateway
{
if
bt
.
conf
.
Select
G
ateway
{
bt
.
addGateways
()
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment