Skip to content

Commit 4970239

Browse files
committed
simulator/ssh: cleanup and doc
Wrap arguments to SSHTransfer.simulate() in struct. Let folks know that we know what we're doing regarding placing a private key within the repo.
1 parent f164ea7 commit 4970239

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

simulator/ssh-transfer.go

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,28 @@ func newClient(
8686
return c, nil
8787
}
8888

89+
type simulationContext struct {
90+
Ctx context.Context
91+
Dst string
92+
ClientName string
93+
Handle string
94+
SendSize bytesize.ByteSize
95+
Signer ssh.Signer
96+
Ch chan<- simssh.WriteResponse
97+
}
98+
8999
// simulate performs the actual client connect and write on behalf of Simulate().
90-
func (s *SSHTransfer) simulate(
91-
ctx context.Context,
92-
dst string,
93-
clientName string,
94-
handle string,
95-
sendSize bytesize.ByteSize,
96-
signer ssh.Signer,
97-
ch chan<- simssh.WriteResponse) {
98-
c, err := newClient(ctx, clientName, s.src, dst, signer)
100+
func (s *SSHTransfer) simulate(simCtx *simulationContext) {
101+
c, err := newClient(simCtx.Ctx, simCtx.ClientName, s.src, simCtx.Dst, simCtx.Signer)
99102
if err != nil {
100103
// Piggy back client connect errors on WriteResponse chan.
101104
res := simssh.WriteResponse{}
102-
res.ClientName = clientName
105+
res.ClientName = simCtx.ClientName
103106
res.Err = err
104-
ch <- res
107+
simCtx.Ch <- res
105108
return
106109
}
107-
ch <- c.WriteRandom(handle, sendSize)
110+
simCtx.Ch <- c.WriteRandom(simCtx.Handle, simCtx.SendSize)
108111
c.Teardown()
109112
}
110113

@@ -128,14 +131,15 @@ func (s *SSHTransfer) Simulate(ctx context.Context, dst string) error {
128131
// write responses.
129132
writeCh := make(chan simssh.WriteResponse, numClients)
130133
for i := 0; i < numClients; i++ {
131-
go s.simulate(
132-
ctx,
133-
dst,
134-
fmt.Sprintf("alphasoc-%v", i),
135-
fmt.Sprintf("flightsim-ssh-transfer-%v", i),
136-
senderSizes[i],
137-
signer,
138-
writeCh)
134+
go s.simulate(&simulationContext{
135+
Ctx: ctx,
136+
Dst: dst,
137+
ClientName: fmt.Sprintf("alphasoc-%v", i),
138+
Handle: fmt.Sprintf("flightsim-ssh-transfer-%v", i),
139+
SendSize: senderSizes[i],
140+
Signer: signer,
141+
Ch: writeCh})
142+
139143
}
140144
var errsEncountered []string
141145
var totalBytesSent bytesize.ByteSize

simulator/ssh/auth.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"golang.org/x/crypto/ssh"
77
)
88

9+
// The private key here is solely used to authenticate with the server-side application
10+
// accpeting the SSH/SFTP data transfer. This is being done on purpose.
911
const privKey = `-----BEGIN OPENSSH PRIVATE KEY-----
1012
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
1113
QyNTUxOQAAACA6El6xrgg3fzl6dbygysFLXmVN3ysbLnbnkD8jpgOAxQAAAJiL5q0ti+at

0 commit comments

Comments
 (0)