Skip to content

Commit

Permalink
change stream i/o log
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Jun 11, 2019
1 parent 440e490 commit b31a9d0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"crypto/sha1"
"fmt"
"io"
"log"
"math/rand"
Expand All @@ -28,7 +29,7 @@ var VERSION = "SELFBUILD"
// A pool for stream copying
var xmitBuf sync.Pool

func handleClient(sess *smux.Session, p1 io.ReadWriteCloser, quiet bool) {
func handleClient(sess *smux.Session, p1 net.Conn, quiet bool) {
logln := func(v ...interface{}) {
if !quiet {
log.Println(v...)
Expand All @@ -43,8 +44,8 @@ func handleClient(sess *smux.Session, p1 io.ReadWriteCloser, quiet bool) {

defer p2.Close()

logln("stream opened", p2.ID(), "@", p2.RemoteAddr())
defer logln("stream closed", p2.ID(), "@", p2.RemoteAddr())
logln("stream opened", "in:", p1.RemoteAddr(), "out:", fmt.Sprint(p2.RemoteAddr(), "(", p2.ID(), ")"))
defer logln("stream closed", "in:", p1.RemoteAddr(), "out:", fmt.Sprint(p2.RemoteAddr(), "(", p2.ID(), ")"))

// start tunnel & wait for tunnel termination
streamCopy := func(dst io.Writer, src io.ReadCloser) chan struct{} {
Expand Down
7 changes: 4 additions & 3 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"crypto/sha1"
"fmt"
"io"
"log"
"math/rand"
Expand Down Expand Up @@ -61,7 +62,7 @@ func handleMux(conn io.ReadWriteCloser, config *Config) {
}
}

func handleClient(p1 *smux.Stream, p2 io.ReadWriteCloser, quiet bool) {
func handleClient(p1 *smux.Stream, p2 net.Conn, quiet bool) {
logln := func(v ...interface{}) {
if !quiet {
log.Println(v...)
Expand All @@ -71,8 +72,8 @@ func handleClient(p1 *smux.Stream, p2 io.ReadWriteCloser, quiet bool) {
defer p1.Close()
defer p2.Close()

logln("stream opened", p1.ID(), "@", p1.RemoteAddr())
defer logln("stream closed", p1.ID(), "@", p1.RemoteAddr())
logln("stream opened", "in:", fmt.Sprint(p1.RemoteAddr(), "(", p1.ID(), ")"), "out:", p2.RemoteAddr())
defer logln("stream closed", "in:", fmt.Sprint(p1.RemoteAddr(), "(", p1.ID(), ")"), "out:", p2.RemoteAddr())

// start tunnel & wait for tunnel termination
streamCopy := func(dst io.Writer, src io.ReadCloser) chan struct{} {
Expand Down

0 comments on commit b31a9d0

Please sign in to comment.