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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Vladimir KozLove
bitmask-vpn
Commits
a62bd8d0
Unverified
Commit
a62bd8d0
authored
4 years ago
by
Kali Kaneko
Browse files
Options
Downloads
Patches
Plain Diff
[feat] probe for the port of our matching helper
parent
89c08708
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/helper/windows.go
+1
-0
1 addition, 0 deletions
pkg/helper/windows.go
pkg/standalone/launcher.go
+50
-7
50 additions, 7 deletions
pkg/standalone/launcher.go
with
51 additions
and
7 deletions
pkg/helper/windows.go
+
1
−
0
View file @
a62bd8d0
...
...
@@ -114,6 +114,7 @@ func initializeService(preferredPort int) {
func
daemonize
()
{}
// runServer does nothing, serveHTTP is called from within Execute in windows
func
runServer
(
port
int
)
{}
func
getOpenvpnPath
()
string
{
...
...
This diff is collapsed.
Click to expand it.
pkg/standalone/launcher.go
+
50
−
7
View file @
a62bd8d0
...
...
@@ -22,21 +22,64 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"strconv"
"strings"
"time"
"0xacab.org/leap/bitmask-vpn/pkg/config"
"0xacab.org/leap/bitmask-vpn/pkg/standalone/bonafide"
)
const
(
helperAddr
=
"http://localhost:7171"
)
type
launcher
struct
{
helperAddr
string
}
const
initialHelperPort
=
7171
func
probeHelperPort
(
port
int
)
int
{
// this should be enough for a local reply
timeout
:=
time
.
Duration
(
500
*
time
.
Millisecond
)
c
:=
http
.
Client
{
Timeout
:
timeout
}
for
{
if
smellsLikeOurHelperSpirit
(
port
,
&
c
)
{
return
port
}
port
++
if
port
>
65535
{
break
}
}
return
0
}
func
smellsLikeOurHelperSpirit
(
port
int
,
c
*
http
.
Client
)
bool
{
uri
:=
"http://localhost:"
+
strconv
.
Itoa
(
port
)
+
"/version"
log
.
Println
(
"probing for helper at"
,
uri
)
resp
,
err
:=
c
.
Get
(
uri
)
if
err
!=
nil
{
return
false
}
if
resp
.
StatusCode
==
200
{
ver
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
defer
resp
.
Body
.
Close
()
if
err
!=
nil
{
return
false
}
if
strings
.
Contains
(
string
(
ver
),
config
.
ApplicationName
)
{
return
true
}
else
{
log
.
Println
(
"Another helper replied to our version request:"
,
string
(
ver
))
}
}
return
false
}
func
newLauncher
()
(
*
launcher
,
error
)
{
return
&
launcher
{},
nil
helperPort
:=
probeHelperPort
(
initialHelperPort
)
helperAddr
:=
"http://localhost:"
+
strconv
.
Itoa
(
helperPort
)
return
&
launcher
{
helperAddr
},
nil
}
func
(
l
*
launcher
)
close
()
error
{
...
...
@@ -77,7 +120,7 @@ func (l *launcher) firewallStop() error {
func
(
l
*
launcher
)
firewallIsUp
()
bool
{
var
isup
bool
=
false
res
,
err
:=
http
.
Post
(
helperAddr
+
"/firewall/isup"
,
""
,
nil
)
res
,
err
:=
http
.
Post
(
l
.
helperAddr
+
"/firewall/isup"
,
""
,
nil
)
if
err
!=
nil
{
return
false
}
...
...
@@ -106,7 +149,7 @@ func (l *launcher) send(path string, body []byte) error {
if
body
!=
nil
{
reader
=
bytes
.
NewReader
(
body
)
}
res
,
err
:=
http
.
Post
(
helperAddr
+
path
,
""
,
reader
)
res
,
err
:=
http
.
Post
(
l
.
helperAddr
+
path
,
""
,
reader
)
if
err
!=
nil
{
return
err
}
...
...
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