Skip to content

Commit

Permalink
ssh: introduce an ID for multiple traced pkt-line connections
Browse files Browse the repository at this point in the history
Since we're multithreaded, unlike Git, let's provide a useful
per-connection ID when we track pkt-line values so that we can
distinguish multiple connections in the trace output.
  • Loading branch information
bk2204 committed Mar 31, 2021
1 parent ac0a4f8 commit 4e9391c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
8 changes: 4 additions & 4 deletions ssh/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type SSHTransfer struct {
}

func NewSSHTransfer(osEnv config.Environment, gitEnv config.Environment, meta *SSHMetadata, operation string) (*SSHTransfer, error) {
conn, err := startConnection(osEnv, gitEnv, meta, operation)
conn, err := startConnection(0, osEnv, gitEnv, meta, operation)
if err != nil {
return nil, err
}
Expand All @@ -32,7 +32,7 @@ func NewSSHTransfer(osEnv config.Environment, gitEnv config.Environment, meta *S
}, nil
}

func startConnection(osEnv config.Environment, gitEnv config.Environment, meta *SSHMetadata, operation string) (*PktlineConnection, error) {
func startConnection(id int, osEnv config.Environment, gitEnv config.Environment, meta *SSHMetadata, operation string) (*PktlineConnection, error) {
exe, args := GetLFSExeAndArgs(osEnv, gitEnv, meta, "git-lfs-transfer", operation)
cmd := subprocess.ExecCommand(exe, args...)
r, err := cmd.StdoutPipe()
Expand All @@ -50,7 +50,7 @@ func startConnection(osEnv config.Environment, gitEnv config.Environment, meta *

var pl Pktline
if osEnv.Bool("GIT_TRACE_PACKET", false) {
pl = &TraceablePktline{pl: pktline.NewPktline(r, w)}
pl = &TraceablePktline{id: id, pl: pktline.NewPktline(r, w)}
} else {
pl = pktline.NewPktline(r, w)
}
Expand Down Expand Up @@ -112,7 +112,7 @@ func (tr *SSHTransfer) setConnectionCount(n int) error {
return err
} else {
for i := count; i < n; i++ {
conn, err := startConnection(tr.osEnv, tr.gitEnv, tr.meta, tr.operation)
conn, err := startConnection(i, tr.osEnv, tr.gitEnv, tr.meta, tr.operation)
if err != nil {
return err
}
Expand Down
15 changes: 8 additions & 7 deletions ssh/pktline.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Pktline interface {
}

type TraceablePktline struct {
id int
pl *pktline.Pktline
}

Expand All @@ -36,9 +37,9 @@ func (tp *TraceablePktline) ReadPacketList() ([]string, error) {
return nil, err
}
if pktLen <= 1 {
tracerx.Printf("packet < %04x", pktLen)
tracerx.Printf("packet %02x < %04x", tp.id, pktLen)
} else {
tracerx.Printf("packet < %s", data)
tracerx.Printf("packet %02x < %s", tp.id, data)
}

if pktLen == 0 {
Expand All @@ -58,9 +59,9 @@ func (tp *TraceablePktline) ReadPacketTextWithLength() (string, int, error) {
}

if pktLen <= 1 {
tracerx.Printf("packet < %04x", pktLen)
tracerx.Printf("packet %02x < %04x", tp.id, pktLen)
} else {
tracerx.Printf("packet < %s", s)
tracerx.Printf("packet %02x < %s", tp.id, s)
}
return s, pktLen, nil
}
Expand All @@ -71,16 +72,16 @@ func (tp *TraceablePktline) WritePacket(b []byte) error {
}

func (tp *TraceablePktline) WritePacketText(s string) error {
tracerx.Printf("packet > %s", s)
tracerx.Printf("packet %02x > %s", tp.id, s)
return tp.pl.WritePacketText(s)
}

func (tp *TraceablePktline) WriteDelim() error {
tracerx.Printf("packet > 0001")
tracerx.Printf("packet %02x > 0001", tp.id)
return tp.pl.WriteDelim()
}

func (tp *TraceablePktline) WriteFlush() error {
tracerx.Printf("packet > 0000")
tracerx.Printf("packet %02x > 0000", tp.id)
return tp.pl.WriteFlush()
}

0 comments on commit 4e9391c

Please sign in to comment.