@@ -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
0 commit comments