diff --git a/demo.jpg b/demo.jpg new file mode 100644 index 0000000..972b4c1 Binary files /dev/null and b/demo.jpg differ diff --git a/ethrs.log b/ethrs.log new file mode 100644 index 0000000..7837e13 --- /dev/null +++ b/ethrs.log @@ -0,0 +1,2 @@ +{"Time":"2022-07-18T16:52:23Z","Title":"","Type":"INFO","Message":"Accepting IP version: ipv4, ipv6"} +{"Time":"2022-07-18T16:52:23Z","Title":"","Type":"INFO","Message":"Listening on port 8888 for TCP \u0026 UDP"} diff --git a/garnish/garnish.go b/garnish/garnish.go index 670787a..1679ce8 100644 --- a/garnish/garnish.go +++ b/garnish/garnish.go @@ -9,6 +9,9 @@ import ( "net/http/httputil" "net/url" "time" + "crypto/tls" + "io/ioutil" + ) const Xcache = "X-Cache" @@ -72,36 +75,55 @@ func (g *garnish) ServeHTTP(rw http.ResponseWriter, r *http.Request, serverAddre return } // garnish connect to the server - conn, err := pan.DialUDP(context.Background(), netaddr.IPPort{}, addr, nil, nil) + //conn, err := pan.DialUDP(context.Background(), netaddr.IPPort{}, addr, nil, nil) + tlsCfg := &tls.Config{ + InsecureSkipVerify: true, + NextProtos: []string{"hello-quic"}, + } + // Set Pinging Selector with active probing on two paths + selector := &pan.PingingSelector{ + Interval: 2 * time.Second, + Timeout: time.Second, + } + selector.SetActive(2) + session, err := pan.DialQUIC(context.Background(), netaddr.IPPort{}, addr, nil, selector, "", tlsCfg, nil) if err != nil { fmt.Println("connect to server error") return } - defer conn.Close() + //defer conn.Close() - nBytes, err := conn.Write([]byte(fmt.Sprintf("garnish message"))) + //nBytes, err := conn.Write([]byte(fmt.Sprintf("garnish message"))) + stream, err := session.OpenStream() if err != nil { - fmt.Print(nBytes) fmt.Println(err) } - - buffer := make([]byte, 16*1024) - if err = conn.SetReadDeadline(time.Now().Add(1 * time.Second)); err != nil { - fmt.Println("SetReadDeadline error") - return + _, err = stream.Write([]byte(fmt.Sprintf("Welcome to Scion"))) + + if err != nil { + fmt.Println(err) } - n, err := conn.Read(buffer) //read to this buffer + + // + stream.Close() + //buffer := make([]byte, 16*1024) + // if err = conn.SetReadDeadline(time.Now().Add(1 * time.Second)); err != nil { + // fmt.Println("SetReadDeadline error") + // return + // } + //n, err := conn.Read(buffer) //read to this buffer + data, err := ioutil.ReadAll(stream) if err != nil { fmt.Println("here") fmt.Println(err) //return } - data := buffer[:n] + //data := buffer[:n] duration := time.Duration(123) * time.Second g.c.store(u, data, duration) _, _ = rw.Write(data) fmt.Println("Store data ") return // fmt.Println(data) - + } diff --git a/main.go b/main.go index 3a73a01..26e573f 100644 --- a/main.go +++ b/main.go @@ -2,17 +2,19 @@ package main import ( "context" + "crypto/tls" "flag" "fmt" "log" + "errors" "net/http" "net/url" - //"time" - + "github.com/lucas-clemente/quic-go" + "io/ioutil" "inet.af/netaddr" - "github.com/bkielbasa/garnish/garnish" "github.com/netsec-ethz/scion-apps/pkg/pan" + "github.com/netsec-ethz/scion-apps/pkg/quicutil" ) func main() { @@ -66,21 +68,19 @@ func runGarnish(address string) { // } // } -//change into scion -func runServer(listen netaddr.IPPort) { - conn, err := pan.ListenUDP(context.Background(), listen, nil) - if err != nil { - fmt.Printf("listen error") - } - //defer conn.Close() - fmt.Print("Hello! ") - fmt.Println(conn.LocalAddr()) - for true { - buffer := make([]byte, 1024*16*1024) - n, from, err := conn.ReadFrom(buffer) +// create work session +func workSession(session quic.Session) error { + for { + stream, err := session.AcceptStream(context.Background()) if err != nil { - fmt.Printf("read error") + return err } + defer stream.Close() + data, err := ioutil.ReadAll(stream) + if err != nil { + return err + } + fmt.Printf("%s\n", data) const msg = ` @@ -93,14 +93,46 @@ func runServer(listen netaddr.IPPort) { SCION banner ` - //msg := fmt.Sprintf("Aaaaa, i love it") - n, err = conn.WriteTo([]byte(msg), from) + _, err = stream.Write([]byte(msg)) + if err != nil { + return err + } + _, err = stream.Write(data) if err != nil { - fmt.Printf("write error") + return err } - fmt.Printf("Wrote %d bytes.\n", n) - //time.Sleep(time.Millisecond * 30) + stream.Close() + } +} +//change into scion +func runServer(listen netaddr.IPPort) { + //conn, err := pan.ListenUDP(context.Background(), listen, nil) + tlsCfg := &tls.Config{ + Certificates: quicutil.MustGenerateSelfSignedCert(), + NextProtos: []string{"hello-quic"}, } + + listener, err := pan.ListenQUIC(context.Background(), listen, nil, tlsCfg, nil) + if err != nil { + fmt.Printf("listen error") + } + defer listener.Close() + //18-ffaa:1:f53,127.0.0.1:1234 + fmt.Println(listener.Addr()) + for { + session, err := listener.Accept(context.Background()) + if err != nil { + fmt.Printf("listener accept error") + } + fmt.Println("New session", session.RemoteAddr()) + go func() { + err := workSession(session) + var errApplication *quic.ApplicationError + if err != nil && !(errors.As(err, &errApplication) && errApplication.ErrorCode == 0) { + fmt.Println(session.RemoteAddr()) + } + }() + } } func panicOnErr(err error) { diff --git a/web.html b/web.html new file mode 100644 index 0000000..e69de29