5 Commits

Author SHA1 Message Date
idk
c11b90dc47 update release 2020-01-16 15:16:34 -05:00
idk
00969e92f7 update release 2020-01-16 15:16:08 -05:00
idk
129579130d add missing conn.go file 2019-12-28 10:53:09 -05:00
idk
b43178746e add missing conn.go file 2019-12-28 10:50:59 -05:00
idk
72dc2b1d74 get rid of outdated examples 2019-12-08 17:02:24 -05:00
7 changed files with 254 additions and 57 deletions

View File

@@ -132,7 +132,7 @@ func NewClientFromOptions(opts ...func(*Client) error) (*Client, error) {
c.reduceIdleQuantity = 1
c.closeIdle = true
c.closeIdleTime = 600000
c.debug = false
c.debug = true
c.sigType = SAMsigTypes[4]
c.id = 0
c.lastaddr = "invalid"

68
conn.go Normal file
View File

@@ -0,0 +1,68 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Henry
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package goSam
import (
"log"
"net"
"time"
)
type Conn struct {
RWC
conn net.Conn
}
func WrapConn(c net.Conn) *Conn {
wrap := Conn{
conn: c,
}
wrap.Reader = NewReadLogger("<", c)
wrap.Writer = NewWriteLogger(">", c)
wrap.RWC.c = c
return &wrap
}
func (c *Conn) LocalAddr() net.Addr {
return c.conn.LocalAddr()
}
func (c *Conn) RemoteAddr() net.Addr {
return c.conn.RemoteAddr()
}
func (c *Conn) SetDeadline(t time.Time) error {
log.Println("WARNING: SetDeadline() not sure this works")
return c.conn.SetDeadline(t)
}
func (c *Conn) SetReadDeadline(t time.Time) error {
log.Println("WARNING: SetReadDeadline() not sure this works")
return c.conn.SetReadDeadline(t)
}
func (c *Conn) SetWriteDeadline(t time.Time) error {
log.Println("WARNING: SetWriteDeadline() not sure this works")
return c.conn.SetWriteDeadline(t)
}

3
debian/changelog vendored
View File

@@ -1,8 +1,9 @@
golang-github-eyedeekay-gosam (0.3.2.1) bionic; urgency=medium
* Get rid of the debug directory, just move it into the source
* Get rid of the old example, just use the one in the README
-- idk <hankhill19580@gmail.com> Fri, 18 May 2019 18:12:21 -0500
-- idk <hankhill19580@gmail.com> Sat, 08 Dec 2019 19:11:41 -0500
golang-github-eyedeekay-gosam (0.3.2.0) bionic; urgency=medium

View File

@@ -1,53 +0,0 @@
package main
import (
"io"
"log"
"net/http"
"os"
"github.com/eyedeekay/goSam"
)
func main() {
//In order to enable debugging, pass the SetDebug(true) option.
//sam, err := goSam.NewClientFromOptions(SetDebug(true))
// create a default sam client
sam, err := goSam.NewDefaultClient()
checkErr(err)
log.Println("Client Created")
// create a transport that uses SAM to dial TCP Connections
tr := &http.Transport{
Dial: sam.Dial,
}
// create a client using this transport
client := &http.Client{Transport: tr}
// send a get request
resp, err := client.Get("http://stats.i2p/")
checkErr(err)
defer resp.Body.Close()
log.Printf("Get returned %+v\n", resp)
// create a file for the response
file, err := os.Create("stats.html")
checkErr(err)
defer file.Close()
// copy the response to the file
_, err = io.Copy(file, resp.Body)
checkErr(err)
log.Println("Done.")
}
func checkErr(err error) {
if err != nil {
log.Fatal(err)
}
}

4
go.mod
View File

@@ -4,8 +4,8 @@ require github.com/eyedeekay/sam3 v0.32.2
//replace github.com/eyedeekay/gosam v0.1.1-0.20190814195658-27e786578944 => github.com/eyedeekay/goSam ./
replace github.com/eyedeekay/gosam v0.1.1-0.20190814195658-27e786578944 => ./
replace github.com/eyedeekay/gosam v0.32.1 => ./
replace github.com/eyedeekay/goSam v0.1.0 => ./
replace github.com/eyedeekay/goSam v0.32.1 => ./
go 1.13

101
rw.go Normal file
View File

@@ -0,0 +1,101 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Henry
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package goSam
import (
"encoding/hex"
"io"
"log"
)
/*
Copy of testing/iotest Read- and WriteLogger, but using %q instead of %x for printing
*/
type writeLogger struct {
prefix string
w io.Writer
}
func (l *writeLogger) Write(p []byte) (n int, err error) {
n, err = l.w.Write(p)
if err != nil {
log.Printf("%s %q: %v", l.prefix, string(p[0:n]), err)
} else {
log.Printf("%s %q", l.prefix, string(p[0:n]))
}
return
}
// NewWriteLogger returns a writer that behaves like w except
// that it logs (using log.Printf) each write to standard error,
// printing the prefix and the hexadecimal data written.
func NewWriteLogger(prefix string, w io.Writer) io.Writer {
return &writeLogger{prefix, w}
}
type readLogger struct {
prefix string
r io.Reader
}
func (l *readLogger) Read(p []byte) (n int, err error) {
n, err = l.r.Read(p)
if err != nil {
log.Printf("%s %q: %v", l.prefix, string(p[0:n]), err)
} else {
log.Printf("%s %q", l.prefix, string(p[0:n]))
}
return
}
// NewReadLogger returns a reader that behaves like r except
// that it logs (using log.Print) each read to standard error,
// printing the prefix and the hexadecimal data written.
func NewReadLogger(prefix string, r io.Reader) io.Reader {
return &readLogger{prefix, r}
}
type readHexLogger struct {
prefix string
r io.Reader
}
func (l *readHexLogger) Read(p []byte) (n int, err error) {
n, err = l.r.Read(p)
if err != nil {
log.Printf("%s (%d bytes) Error: %v", l.prefix, n, err)
} else {
log.Printf("%s (%d bytes)", l.prefix, n)
}
log.Print("\n" + hex.Dump(p[:n]))
return
}
// NewReadHexLogger returns a reader that behaves like r except
// that it logs to stderr using ecoding/hex.
func NewReadHexLogger(prefix string, r io.Reader) io.Reader {
return &readHexLogger{prefix, r}
}

80
rwc.go Normal file
View File

@@ -0,0 +1,80 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Henry
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package goSam
import (
"io"
//"github.com/miolini/datacounter"
)
type RWC struct {
io.Reader
io.Writer
c io.Closer
}
func WrapRWC(c io.ReadWriteCloser) io.ReadWriteCloser {
rl := NewReadLogger("<", c)
wl := NewWriteLogger(">", c)
return &RWC{
Reader: rl,
Writer: wl,
c: c,
}
}
func (c *RWC) Close() error {
return c.c.Close()
}
/*
type Counter struct {
io.Reader
io.Writer
c io.Closer
Cr *datacounter.ReaderCounter
Cw *datacounter.WriterCounter
}
func WrapCounter(c io.ReadWriteCloser) *Counter {
rc := datacounter.NewReaderCounter(c)
wc := datacounter.NewWriterCounter(c)
return &Counter{
Reader: rc,
Writer: wc,
c: c,
Cr: rc,
Cw: wc,
}
}
func (c *Counter) Close() error {
return c.c.Close()
}
*/