Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TCP relay block when first packet includes payload #37

Closed
cute opened this issue Apr 18, 2017 · 12 comments
Closed

TCP relay block when first packet includes payload #37

cute opened this issue Apr 18, 2017 · 12 comments
Labels

Comments

@cute
Copy link

cute commented Apr 18, 2017

when I copy left buffer manually at first, it is woking.

func relay(left, right net.Conn) (int64, int64, error) {
	type res struct {
		N   int64
		Err error
	}

	ch := make(chan res)

	buf := make([]byte, 1024)
	for {
		nread, _ := left.Read(buf)
		if nread > 0 {
			right.Write(buf[0:nread])
		}
		if nread != 1024 {
			break
		}
	}

	go func() {
		n, err := io.Copy(right, left)
		right.SetDeadline(time.Now()) // wake up the other goroutine blocking on right
		left.SetDeadline(time.Now())  // wake up the other goroutine blocking on left
		ch <- res{n, err}
	}()

	n, err := io.Copy(left, right)
	right.SetDeadline(time.Now()) // wake up the other goroutine blocking on right
	left.SetDeadline(time.Now())  // wake up the other goroutine blocking on left
	rs := <-ch

	if err == nil {
		err = rs.Err
	}
	return n, rs.N, err
}
@riobard
Copy link

riobard commented Apr 18, 2017

Sorry I didn't understand the problem. What happened here? And what's the step to reproduce it?

@cute
Copy link
Author

cute commented Apr 19, 2017

@riobard

go-shadowsocks2 client use socks5 proxy protocol, send address to server at first,
then send request header to server.
but my client use http proxy protocol, send address and request header to server.

@riobard
Copy link

riobard commented Apr 19, 2017

Are you using go-shadowsocks2 as an HTTP proxy?

@cute
Copy link
Author

cute commented Apr 19, 2017

no, i write a shadowsocks client that provides http proxy.

@riobard
Copy link

riobard commented Apr 19, 2017

Sorry I'm confused. Is this issue a bug report? What was wrong here?

@arthurkiller
Copy link

arthurkiller commented Apr 21, 2017

@cute Maybe you'd better read the comments about the io.Copy()

// Copy copies from src to dst until either EOF is reached
// on src or an error occurs. It returns the number of bytes
// copied and the first error encountered while copying, if any.
//
// A successful Copy returns err == nil, not err == EOF.
// Because Copy is defined to read from src until EOF, it does
// not treat an EOF from Read as an error to be reported.
//
// If src implements the WriterTo interface,
// the copy is implemented by calling src.WriteTo(dst).
// Otherwise, if dst implements the ReaderFrom interface,
// the copy is implemented by calling dst.ReadFrom(src).

I think they can do same thing

@cute cute changed the title TDP relay block when first packet includes payload TCP relay block when first packet includes payload Apr 25, 2017
@cute
Copy link
Author

cute commented Apr 25, 2017

@riobard
shadowsocks tcp protocol is [target address][payload], http request through local proxy:

local socks5 proxy send data to server:

write [target address]
write [payload]
read

local http proxy send data to server:

write [target address][payload]
read

If address and payload is sent together, server can not process the data correctly.

@riobard
Copy link

riobard commented Apr 25, 2017

I think I understand the problem now. Do you have a code snippet to reproduce the bug?

@cute
Copy link
Author

cute commented Apr 25, 2017

@riobard what's your email? I want to send you an iOS app promotion code.

@riobard
Copy link

riobard commented Apr 25, 2017

Got the code. What's the step to reproduce the bug?

@riobard
Copy link

riobard commented Apr 25, 2017

Problem identified: this is actually caused by a bug in the implementation of AEAD stream reader. The fix has been committed into my fork here riobard@de996c8 and a new test release is created at https://github.com/riobard/go-shadowsocks2/releases/tag/v0.0.9

@riobard riobard added the bug label Apr 25, 2017
@riobard
Copy link

riobard commented Apr 26, 2017

Fixed by #40

@riobard riobard closed this as completed Apr 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants