Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7cf9e8b61e | ||
![]() |
c7d6848930 | ||
![]() |
eabd2d94f6 | ||
![]() |
76924e5961 | ||
![]() |
027983674b | ||
![]() |
7521a7862a | ||
![]() |
c11b90dc47 | ||
![]() |
00969e92f7 | ||
![]() |
129579130d | ||
![]() |
b43178746e | ||
![]() |
72dc2b1d74 |
24
Makefile
Normal file
24
Makefile
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
USER_GH=eyedeekay
|
||||
VERSION=0.32.24
|
||||
packagename=gosam
|
||||
|
||||
echo:
|
||||
@echo "type make version to do release $(VERSION)"
|
||||
|
||||
version:
|
||||
gothub release -s $(GITHUB_TOKEN) -u $(USER_GH) -r $(packagename) -t v$(VERSION) -d "version $(VERSION)"
|
||||
|
||||
del:
|
||||
gothub delete -s $(GITHUB_TOKEN) -u $(USER_GH) -r $(packagename) -t v$(VERSION)
|
||||
|
||||
tar:
|
||||
tar --exclude .git \
|
||||
--exclude .go \
|
||||
--exclude bin \
|
||||
--exclude examples \
|
||||
-cJvf ../$(packagename)_$(VERSION).orig.tar.xz .
|
||||
|
||||
link:
|
||||
rm -f ../goSam
|
||||
ln -sf . ../goSam
|
@@ -11,6 +11,7 @@ import (
|
||||
"math/rand"
|
||||
"net"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// A Client represents a single Connection to the SAM bridge
|
||||
@@ -52,6 +53,7 @@ type Client struct {
|
||||
//NEVER, EVER modify lastaddr or id yourself. They are used internally only.
|
||||
lastaddr string
|
||||
id int32
|
||||
ml sync.Mutex
|
||||
}
|
||||
|
||||
var SAMsigTypes = []string{
|
||||
@@ -132,7 +134,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
68
conn.go
Normal 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)
|
||||
}
|
15
debian/changelog
vendored
15
debian/changelog
vendored
@@ -1,8 +1,21 @@
|
||||
golang-github-eyedeekay-gosam (0.32.24) UNRELEASED; urgency=medium
|
||||
|
||||
* Improve the mutex thingy
|
||||
|
||||
-- idk <hankhill19580@gmail.com> Tue, 25 Aug 2020 04:52:11 -0500
|
||||
|
||||
golang-github-eyedeekay-gosam (0.32.23) UNRELEASED; urgency=medium
|
||||
|
||||
* Protect Dial with a mutex to fix a lookup bug
|
||||
|
||||
-- idk <hankhill19580@gmail.com> Tue, 25 Aug 2020 10:29:26 -0500
|
||||
|
||||
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
|
||||
|
||||
|
3
debian/control
vendored
3
debian/control
vendored
@@ -6,7 +6,8 @@ Uploaders: idk <hankhill19580@gmail.com>
|
||||
Build-Depends: debhelper (>= 11),
|
||||
dh-golang,
|
||||
golang-any,
|
||||
i2pd | i2p
|
||||
i2pd | i2p,
|
||||
git,
|
||||
Standards-Version: 4.2.1
|
||||
Homepage: https://github.com/eyedeekay/gosam
|
||||
Vcs-Browser: https:/github.com/eyedeekay/gosam
|
||||
|
1
debian/files
vendored
Normal file
1
debian/files
vendored
Normal file
@@ -0,0 +1 @@
|
||||
golang-github-eyedeekay-gosam_0.32.23_source.buildinfo devel optional
|
5
dial.go
5
dial.go
@@ -34,12 +34,17 @@ func (c Client) dialCheck(addr string) (int32, bool) {
|
||||
if c.lastaddr == "invalid" {
|
||||
fmt.Println("Preparing to dial new address.")
|
||||
return c.NewID(), true
|
||||
} else if c.lastaddr != addr {
|
||||
fmt.Println("Preparing to dial next new address.")
|
||||
return c.NewID(), true
|
||||
}
|
||||
return c.id, false
|
||||
}
|
||||
|
||||
// Dial implements the net.Dial function and can be used for http.Transport
|
||||
func (c *Client) Dial(network, addr string) (net.Conn, error) {
|
||||
c.ml.Lock()
|
||||
defer c.ml.Unlock()
|
||||
portIdx := strings.Index(addr, ":")
|
||||
if portIdx >= 0 {
|
||||
addr = addr[:portIdx]
|
||||
|
@@ -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
4
go.mod
@@ -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
|
||||
|
3
go.sum
Normal file
3
go.sum
Normal file
@@ -0,0 +1,3 @@
|
||||
github.com/eyedeekay/ramp v0.0.0-20190429201811-305b382042ab/go.mod h1:h7mvUAMgZ/rtRDUOkvKTK+8LnDMeUhJSoa5EPdB51fc=
|
||||
github.com/eyedeekay/sam3 v0.32.2 h1:xODDY5nBVg0oK7KaYk7ofkXFoHPsmI1umhSv1TZlS7s=
|
||||
github.com/eyedeekay/sam3 v0.32.2/go.mod h1:Y3igFVzN4ybqkkpfUWULGhw7WRp8lieq0ORXbLBbcZM=
|
@@ -22,8 +22,8 @@ func TestClientLookupInvalid(t *testing.T) {
|
||||
if !ok {
|
||||
t.Fatalf("client.Lookup() should return a ReplyError")
|
||||
}
|
||||
if repErr.Result != ResultInvalidKey {
|
||||
t.Errorf("client.Lookup() should throw an ResultKeyNotFound error.\nGot:%+v\n", repErr)
|
||||
if repErr.Result != ResultKeyNotFound {
|
||||
t.Errorf("client.Lookup() should throw an ResultKeyNotFound error.\nGot:%+v%s%s\n", repErr, "!=", Result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TOOlNzdpne8cuesn3NDXIpNnqEE6Oe5Qm5YOJykrX~Vx~cFFT3QzDGkIjjxlFBsjUJyYkFjBQAEAAcAAA==
|
||||
}
|
||||
|
101
rw.go
Normal file
101
rw.go
Normal 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
80
rwc.go
Normal 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()
|
||||
}
|
||||
*/
|
Reference in New Issue
Block a user