Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Hi nf: I fix some build error, and let it work for Go 1; Give a more clear log at some point #1

Merged
merged 1 commit into from almost 2 years ago

2 participants

Kicool Zhang Andrew Gerrand
Kicool Zhang

No description provided.

Andrew Gerrand nf merged commit d0fdefa into from April 25, 2012
Andrew Gerrand nf closed this April 25, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Apr 11, 2012
Kicool Zhang fix for Go1; modify some logs dc5ae2b
This page is out of date. Refresh to see the latest.
11  tun-client/client.go
@@ -3,11 +3,11 @@ package main
3 3
 import (
4 4
 	"bytes"
5 5
 	"flag"
6  
-	"http"
7 6
 	"io"
8 7
 	"io/ioutil"
9 8
 	"log"
10 9
 	"net"
  10
+	"net/http"
11 11
 	"time"
12 12
 )
13 13
 
@@ -40,21 +40,24 @@ func makeReadChan(r io.Reader, bufSize int) chan []byte {
40 40
 
41 41
 func main() {
42 42
 	flag.Parse()
  43
+	log.SetPrefix("httptun.c: ")
43 44
 
44 45
 	listener, err := net.Listen("tcp", *listenAddr)
45 46
 	if err != nil {
46 47
 		panic(err)
47 48
 	}
  49
+	log.Println("listen", *listenAddr)
48 50
 
49 51
 	conn, err := listener.Accept()
50 52
 	if err != nil {
51 53
 		panic(err)
52 54
 	}
  55
+	log.Println("accept conn", "localAddr.", conn.LocalAddr(), "remoteAddr.", conn.RemoteAddr())
53 56
 
54 57
 	buf := new(bytes.Buffer)
55 58
 
56 59
 	// initiate new session and read key
57  
-	log.Println("Attempting connect", *destAddr)
  60
+	log.Println("Attempting connect HttpTun Server.", *httpAddr, "for dest.", *destAddr)
58 61
 	buf.Write([]byte(*destAddr))
59 62
 	resp, err := http.Post(
60 63
 		"http://"+*httpAddr+"/create",
@@ -69,7 +72,7 @@ func main() {
69 72
 	log.Println("ResponseWriterected, key", key)
70 73
 
71 74
 	// ticker to set a rate at which to hit the server
72  
-	tick := time.NewTicker(int64(*tickInterval) * 1e6)
  75
+	tick := time.NewTicker(time.Duration(int64(*tickInterval)) * time.Millisecond)
73 76
 	read := makeReadChan(conn, bufSize)
74 77
 	buf.Reset()
75 78
 	for {
@@ -83,7 +86,7 @@ func main() {
83 86
 				"application/octet-stream",
84 87
 				req)
85 88
 			if err != nil {
86  
-				log.Println(err.String())
  89
+				log.Println(err.Error())
87 90
 				continue
88 91
 			}
89 92
 			// write http response response to conn
14  tun-server/server.go
@@ -2,17 +2,17 @@ package main
2 2
 
3 3
 import (
4 4
 	"flag"
5  
-	"http"
6 5
 	"io"
7 6
 	"io/ioutil"
8 7
 	"log"
  8
+	"math/rand"
9 9
 	"net"
10  
-	"os"
11  
-	"rand"
  10
+	"net/http"
  11
+	"time"
12 12
 )
13 13
 
14 14
 const (
15  
-	readTimeout = 100e6
  15
+	readTimeout = 100
16 16
 	keyLen      = 64
17 17
 )
18 18
 
@@ -28,14 +28,14 @@ type proxyPacket struct {
28 28
 	done chan bool
29 29
 }
30 30
 
31  
-func NewProxy(key, destAddr string) (p *proxy, err os.Error) {
  31
+func NewProxy(key, destAddr string) (p *proxy, err error) {
32 32
 	p = &proxy{C: make(chan proxyPacket), key: key}
33 33
 	log.Println("Attempting connect", destAddr)
34 34
 	p.conn, err = net.Dial("tcp", destAddr)
35 35
 	if err != nil {
36 36
 		return
37 37
 	}
38  
-	p.conn.SetReadTimeout(readTimeout)
  38
+	p.conn.SetReadDeadline(time.Now().Add(time.Millisecond*readTimeout))
39 39
 	log.Println("ResponseWriterected", destAddr)
40 40
 	return
41 41
 }
@@ -44,7 +44,7 @@ func (p *proxy) handle(pp proxyPacket) {
44 44
 	// read from the request body and write to the ResponseWriter
45 45
 	_, err := io.Copy(p.conn, pp.r.Body)
46 46
 	pp.r.Body.Close()
47  
-	if err == os.EOF {
  47
+	if err == io.EOF {
48 48
 		p.conn = nil
49 49
 		log.Println("eof", p.key)
50 50
 		return
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.