Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
41266223
Commit
41266223
authored
Jun 18, 2015
by
Daniel Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix locking around ssh tunnels
parent
847d7711
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
7 deletions
+36
-7
master.go
pkg/master/master.go
+18
-3
ssh.go
pkg/util/ssh.go
+18
-4
No files found.
pkg/master/master.go
View file @
41266223
...
@@ -20,6 +20,7 @@ import (
...
@@ -20,6 +20,7 @@ import (
"bytes"
"bytes"
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"math/rand"
"net"
"net"
"net/http"
"net/http"
"net/http/pprof"
"net/http/pprof"
...
@@ -774,9 +775,23 @@ func findExternalAddress(node *api.Node) (string, error) {
...
@@ -774,9 +775,23 @@ func findExternalAddress(node *api.Node) (string, error) {
}
}
func
(
m
*
Master
)
Dial
(
net
,
addr
string
)
(
net
.
Conn
,
error
)
{
func
(
m
*
Master
)
Dial
(
net
,
addr
string
)
(
net
.
Conn
,
error
)
{
m
.
tunnelsLock
.
Lock
()
// Only lock while picking a tunnel.
defer
m
.
tunnelsLock
.
Unlock
()
tunnel
,
err
:=
func
()
(
util
.
SSHTunnelEntry
,
error
)
{
return
m
.
tunnels
.
Dial
(
net
,
addr
)
m
.
tunnelsLock
.
Lock
()
defer
m
.
tunnelsLock
.
Unlock
()
return
m
.
tunnels
.
PickRandomTunnel
()
}()
if
err
!=
nil
{
return
nil
,
err
}
start
:=
time
.
Now
()
id
:=
rand
.
Int63
()
// So you can match begins/ends in the log.
glog
.
V
(
3
)
.
Infof
(
"[%x: %v] Dialing..."
,
id
,
tunnel
.
Address
)
defer
func
()
{
glog
.
V
(
3
)
.
Infof
(
"[%x: %v] Dialed in %v."
,
id
,
tunnel
.
Address
,
time
.
Now
()
.
Sub
(
start
))
}()
return
tunnel
.
Tunnel
.
Dial
(
net
,
addr
)
}
}
func
(
m
*
Master
)
needToReplaceTunnels
(
addrs
[]
string
)
bool
{
func
(
m
*
Master
)
needToReplaceTunnels
(
addrs
[]
string
)
bool
{
...
...
pkg/util/ssh.go
View file @
41266223
...
@@ -81,8 +81,8 @@ func NewSSHTunnel(user, keyfile, host string) (*SSHTunnel, error) {
...
@@ -81,8 +81,8 @@ func NewSSHTunnel(user, keyfile, host string) (*SSHTunnel, error) {
return
makeSSHTunnel
(
user
,
signer
,
host
)
return
makeSSHTunnel
(
user
,
signer
,
host
)
}
}
func
NewSSHTunnelFromBytes
(
user
string
,
buffer
[]
byte
,
host
string
)
(
*
SSHTunnel
,
error
)
{
func
NewSSHTunnelFromBytes
(
user
string
,
privateKey
[]
byte
,
host
string
)
(
*
SSHTunnel
,
error
)
{
signer
,
err
:=
MakePrivateKeySignerFromBytes
(
buffer
)
signer
,
err
:=
MakePrivateKeySignerFromBytes
(
privateKey
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -214,11 +214,13 @@ func ParsePublicKeyFromFile(keyFile string) (*rsa.PublicKey, error) {
...
@@ -214,11 +214,13 @@ func ParsePublicKeyFromFile(keyFile string) (*rsa.PublicKey, error) {
return
rsaKey
,
nil
return
rsaKey
,
nil
}
}
// Should be thread safe.
type
SSHTunnelEntry
struct
{
type
SSHTunnelEntry
struct
{
Address
string
Address
string
Tunnel
*
SSHTunnel
Tunnel
*
SSHTunnel
}
}
// Not thread safe!
type
SSHTunnelList
struct
{
type
SSHTunnelList
struct
{
entries
[]
SSHTunnelEntry
entries
[]
SSHTunnelEntry
}
}
...
@@ -271,11 +273,23 @@ func (l *SSHTunnelList) Close() {
...
@@ -271,11 +273,23 @@ func (l *SSHTunnelList) Close() {
}
}
}
}
/* this will make sense if we move the lock into SSHTunnelList.
func (l *SSHTunnelList) Dial(network, addr string) (net.Conn, error) {
func (l *SSHTunnelList) Dial(network, addr string) (net.Conn, error) {
if len(l.entries) == 0 {
if len(l.entries) == 0 {
return
nil
,
fmt
.
Errorf
(
"
E
mpty tunnel list."
)
return nil, fmt.Errorf("
e
mpty tunnel list.")
}
}
return
l
.
entries
[
mathrand
.
Int
()
%
len
(
l
.
entries
)]
.
Tunnel
.
Dial
(
network
,
addr
)
n := mathrand.Intn(len(l.entries))
return l.entries[n].Tunnel.Dial(network, addr)
}
*/
// Returns a random tunnel, xor an error if there are none.
func
(
l
*
SSHTunnelList
)
PickRandomTunnel
()
(
SSHTunnelEntry
,
error
)
{
if
len
(
l
.
entries
)
==
0
{
return
SSHTunnelEntry
{},
fmt
.
Errorf
(
"empty tunnel list."
)
}
n
:=
mathrand
.
Intn
(
len
(
l
.
entries
))
return
l
.
entries
[
n
],
nil
}
}
func
(
l
*
SSHTunnelList
)
Has
(
addr
string
)
bool
{
func
(
l
*
SSHTunnelList
)
Has
(
addr
string
)
bool
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment