mirror of
https://github.com/go-i2p/onramp.git
synced 2025-07-12 19:04:52 -04:00
don't log in GetJoinedWD for now because it is called prior to
This commit is contained in:
13
common.go
13
common.go
@ -4,12 +4,13 @@
|
|||||||
package onramp
|
package onramp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate go run -tags gen ./gen.go
|
//go:generate go run -tags gen ./gen.go
|
||||||
@ -18,23 +19,23 @@ import (
|
|||||||
func GetJoinedWD(dir string) (string, error) {
|
func GetJoinedWD(dir string) (string, error) {
|
||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("Failed to get working directory")
|
//log.WithError(err).Error("Failed to get working directory")
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
jwd := filepath.Join(wd, dir)
|
jwd := filepath.Join(wd, dir)
|
||||||
ajwd, err := filepath.Abs(jwd)
|
ajwd, err := filepath.Abs(jwd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).WithField("path", jwd).Error("Failed to get absolute path")
|
//log.WithError(err).WithField("path", jwd).Error("Failed to get absolute path")
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if _, err := os.Stat(ajwd); err != nil {
|
if _, err := os.Stat(ajwd); err != nil {
|
||||||
log.WithField("path", ajwd).Debug("Directory does not exist, creating")
|
//log.WithField("path", ajwd).Debug("Directory does not exist, creating")
|
||||||
if err := os.MkdirAll(ajwd, 0755); err != nil {
|
if err := os.MkdirAll(ajwd, 0755); err != nil {
|
||||||
log.WithError(err).WithField("path", ajwd).Error("Failed to create directory")
|
//log.WithError(err).WithField("path", ajwd).Error("Failed to create directory")
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.WithField("path", ajwd).Debug("Successfully got joined working directory")
|
//log.WithField("path", ajwd).Debug("Successfully got joined working directory")
|
||||||
return ajwd, nil
|
return ajwd, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
23
garlic.go
23
garlic.go
@ -7,12 +7,13 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/go-i2p/i2pkeys"
|
"github.com/go-i2p/i2pkeys"
|
||||||
"github.com/go-i2p/sam3"
|
"github.com/go-i2p/sam3"
|
||||||
)
|
)
|
||||||
@ -75,7 +76,7 @@ func (g *Garlic) String() string {
|
|||||||
default:
|
default:
|
||||||
r = g.ServiceKeys.Address.DestHash().Hash()
|
r = g.ServiceKeys.Address.DestHash().Hash()
|
||||||
}
|
}
|
||||||
return g.addrString(r) //r //strings.TrimLeft(strings.TrimRight(r, "\n"), "\n") //strings.TrimSpace(r)
|
return g.addrString(r) // r //strings.TrimLeft(strings.TrimRight(r, "\n"), "\n") //strings.TrimSpace(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Garlic) getName() string {
|
func (g *Garlic) getName() string {
|
||||||
@ -175,7 +176,7 @@ func (g *Garlic) NewListener(n, addr string) (net.Listener, error) {
|
|||||||
|
|
||||||
log.Debug("Successfully created listener")
|
log.Debug("Successfully created listener")
|
||||||
return listener, nil
|
return listener, nil
|
||||||
//return g.Listen(n)
|
// return g.Listen(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listen returns a net.Listener for the Garlic structure's I2P keys.
|
// Listen returns a net.Listener for the Garlic structure's I2P keys.
|
||||||
@ -194,7 +195,7 @@ func (g *Garlic) Listen(args ...string) (net.Listener, error) {
|
|||||||
|
|
||||||
log.Debug("Successfully created listener")
|
log.Debug("Successfully created listener")
|
||||||
return listener, nil
|
return listener, nil
|
||||||
//return g.OldListen(args...)
|
// return g.OldListen(args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OldListen returns a net.Listener for the Garlic structure's I2P keys.
|
// OldListen returns a net.Listener for the Garlic structure's I2P keys.
|
||||||
@ -204,7 +205,7 @@ func (g *Garlic) OldListen(args ...string) (net.Listener, error) {
|
|||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
protocol := args[0]
|
protocol := args[0]
|
||||||
log.WithField("protocol", protocol).Debug("Checking protocol type")
|
log.WithField("protocol", protocol).Debug("Checking protocol type")
|
||||||
//if args[0] == "tcp" || args[0] == "tcp6" || args[0] == "st" || args[0] == "st6" {
|
// if args[0] == "tcp" || args[0] == "tcp6" || args[0] == "st" || args[0] == "st6" {
|
||||||
if protocol == "tcp" || protocol == "tcp6" || protocol == "st" || protocol == "st6" {
|
if protocol == "tcp" || protocol == "tcp6" || protocol == "st" || protocol == "st6" {
|
||||||
log.Debug("Using TCP stream listener")
|
log.Debug("Using TCP stream listener")
|
||||||
return g.ListenStream()
|
return g.ListenStream()
|
||||||
@ -284,7 +285,7 @@ func (g *Garlic) ListenTLS(args ...string) (net.Listener, error) {
|
|||||||
protocol := args[0]
|
protocol := args[0]
|
||||||
log.WithField("protocol", protocol).Debug("Creating TLS listener for protocol")
|
log.WithField("protocol", protocol).Debug("Creating TLS listener for protocol")
|
||||||
|
|
||||||
//if args[0] == "tcp" || args[0] == "tcp6" || args[0] == "st" || args[0] == "st6" {
|
// if args[0] == "tcp" || args[0] == "tcp6" || args[0] == "st" || args[0] == "st6" {
|
||||||
if protocol == "tcp" || protocol == "tcp6" || protocol == "st" || protocol == "st6" {
|
if protocol == "tcp" || protocol == "tcp6" || protocol == "st" || protocol == "st6" {
|
||||||
log.Debug("Creating TLS stream listener")
|
log.Debug("Creating TLS stream listener")
|
||||||
return tls.NewListener(
|
return tls.NewListener(
|
||||||
@ -344,7 +345,7 @@ func (g *Garlic) Dial(net, addr string) (net.Conn, error) {
|
|||||||
}
|
}
|
||||||
log.Debug("Successfully established connection")
|
log.Debug("Successfully established connection")
|
||||||
return conn, nil
|
return conn, nil
|
||||||
//return g.StreamSession.Dial(net, addr)
|
// return g.StreamSession.Dial(net, addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DialContext returns a net.Conn for the Garlic structure's I2P keys.
|
// DialContext returns a net.Conn for the Garlic structure's I2P keys.
|
||||||
@ -375,7 +376,7 @@ func (g *Garlic) DialContext(ctx context.Context, net, addr string) (net.Conn, e
|
|||||||
|
|
||||||
log.Debug("Successfully established connection")
|
log.Debug("Successfully established connection")
|
||||||
return conn, nil
|
return conn, nil
|
||||||
//return g.StreamSession.DialContext(ctx, net, addr)
|
// return g.StreamSession.DialContext(ctx, net, addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close closes the Garlic structure's sessions and listeners.
|
// Close closes the Garlic structure's sessions and listeners.
|
||||||
@ -422,7 +423,7 @@ func (g *Garlic) Keys() (*i2pkeys.I2PKeys, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *Garlic) DeleteKeys() error {
|
func (g *Garlic) DeleteKeys() error {
|
||||||
//return DeleteGarlicKeys(g.getName())
|
// return DeleteGarlicKeys(g.getName())
|
||||||
log.WithField("name", g.getName()).Debug("Attempting to delete Garlic keys")
|
log.WithField("name", g.getName()).Debug("Attempting to delete Garlic keys")
|
||||||
err := DeleteGarlicKeys(g.getName())
|
err := DeleteGarlicKeys(g.getName())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -561,7 +562,7 @@ func CloseGarlic(tunName string) {
|
|||||||
g, ok := garlics[tunName]
|
g, ok := garlics[tunName]
|
||||||
if ok {
|
if ok {
|
||||||
log.Debug("Found Garlic connection, closing")
|
log.Debug("Found Garlic connection, closing")
|
||||||
//g.Close()
|
// g.Close()
|
||||||
err := g.Close()
|
err := g.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("Error closing Garlic connection")
|
log.WithError(err).Error("Error closing Garlic connection")
|
||||||
@ -621,5 +622,5 @@ func DialGarlic(network, addr string) (net.Conn, error) {
|
|||||||
|
|
||||||
log.Debug("Successfully established Garlic connection")
|
log.Debug("Successfully established Garlic connection")
|
||||||
return conn, nil
|
return conn, nil
|
||||||
//return g.Dial(network, addr)
|
// return g.Dial(network, addr)
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,14 @@ package onramp
|
|||||||
|
|
||||||
import "github.com/go-i2p/sam3"
|
import "github.com/go-i2p/sam3"
|
||||||
|
|
||||||
var OPT_DEFAULTS = sam3.Options_Default
|
var (
|
||||||
var OPT_WIDE = sam3.Options_Wide
|
OPT_DEFAULTS = sam3.Options_Default
|
||||||
|
OPT_WIDE = sam3.Options_Wide
|
||||||
|
)
|
||||||
|
|
||||||
var OPT_HUGE = sam3.Options_Humongous
|
var (
|
||||||
var OPT_LARGE = sam3.Options_Large
|
OPT_HUGE = sam3.Options_Humongous
|
||||||
var OPT_MEDIUM = sam3.Options_Medium
|
OPT_LARGE = sam3.Options_Large
|
||||||
var OPT_SMALL = sam3.Options_Small
|
OPT_MEDIUM = sam3.Options_Medium
|
||||||
|
OPT_SMALL = sam3.Options_Small
|
||||||
|
)
|
||||||
|
3
log.go
3
log.go
@ -1,11 +1,12 @@
|
|||||||
package onramp
|
package onramp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
23
onion.go
23
onion.go
@ -7,11 +7,12 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/cretz/bine/tor"
|
"github.com/cretz/bine/tor"
|
||||||
"github.com/cretz/bine/torutil/ed25519"
|
"github.com/cretz/bine/torutil/ed25519"
|
||||||
)
|
)
|
||||||
@ -70,7 +71,7 @@ func (o *Onion) getTor() *tor.Tor {
|
|||||||
torp, err = tor.Start(o.getContext(), o.getStartConf())
|
torp, err = tor.Start(o.getContext(), o.getStartConf())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("Failed to start Tor")
|
log.WithError(err).Error("Failed to start Tor")
|
||||||
panic(err) //return nil instead?
|
panic(err) // return nil instead?
|
||||||
}
|
}
|
||||||
log.Debug("Tor instance started successfully")
|
log.Debug("Tor instance started successfully")
|
||||||
}
|
}
|
||||||
@ -78,9 +79,9 @@ func (o *Onion) getTor() *tor.Tor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (o *Onion) getDialer() *tor.Dialer {
|
func (o *Onion) getDialer() *tor.Dialer {
|
||||||
//if o.Dialer == nil {
|
// if o.Dialer == nil {
|
||||||
//var err error
|
// var err error
|
||||||
//o.Dialer, err
|
// o.Dialer, err
|
||||||
log.Debug("Creating new Tor dialer")
|
log.Debug("Creating new Tor dialer")
|
||||||
dialer, err := o.getTor().Dialer(o.getContext(), o.getDialConf())
|
dialer, err := o.getTor().Dialer(o.getContext(), o.getDialConf())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -123,7 +124,7 @@ func (o *Onion) Listen(args ...string) (net.Listener, error) {
|
|||||||
|
|
||||||
log.Debug("Successfully created Onion listener")
|
log.Debug("Successfully created Onion listener")
|
||||||
return listener, nil
|
return listener, nil
|
||||||
//return o.OldListen(args...)
|
// return o.OldListen(args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OldListen returns a net.Listener which will listen on an onion
|
// OldListen returns a net.Listener which will listen on an onion
|
||||||
@ -140,7 +141,7 @@ func (o *Onion) OldListen(args ...string) (net.Listener, error) {
|
|||||||
|
|
||||||
log.Debug("Successfully created Tor listener")
|
log.Debug("Successfully created Tor listener")
|
||||||
return listener, nil
|
return listener, nil
|
||||||
//return o.getTor().Listen(o.getContext(), o.getListenConf())
|
// return o.getTor().Listen(o.getContext(), o.getListenConf())
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListenTLS returns a net.Listener which will apply TLS encryption
|
// ListenTLS returns a net.Listener which will apply TLS encryption
|
||||||
@ -182,7 +183,7 @@ func (o *Onion) Dial(net, addr string) (net.Conn, error) {
|
|||||||
|
|
||||||
log.Debug("Successfully established Tor connection")
|
log.Debug("Successfully established Tor connection")
|
||||||
return conn, nil
|
return conn, nil
|
||||||
//return o.getDialer().DialContext(o.getContext(), net, addr)
|
// return o.getDialer().DialContext(o.getContext(), net, addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close closes the Onion Service and all associated resources.
|
// Close closes the Onion Service and all associated resources.
|
||||||
@ -197,7 +198,7 @@ func (o *Onion) Close() error {
|
|||||||
|
|
||||||
log.Debug("Successfully closed Onion service")
|
log.Debug("Successfully closed Onion service")
|
||||||
return nil
|
return nil
|
||||||
//return o.getTor().Close()
|
// return o.getTor().Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keys returns the keys for the Onion
|
// Keys returns the keys for the Onion
|
||||||
@ -212,7 +213,7 @@ func (o *Onion) Keys() (ed25519.KeyPair, error) {
|
|||||||
|
|
||||||
log.Debug("Successfully retrieved Onion keys")
|
log.Debug("Successfully retrieved Onion keys")
|
||||||
return keys, nil
|
return keys, nil
|
||||||
//return TorKeys(o.getName())
|
// return TorKeys(o.getName())
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteKeys deletes the keys at the given key name in the key store.
|
// DeleteKeys deletes the keys at the given key name in the key store.
|
||||||
@ -343,7 +344,7 @@ func ListenOnion(network, keys string) (net.Listener, error) {
|
|||||||
|
|
||||||
log.Debug("Successfully created Onion listener")
|
log.Debug("Successfully created Onion listener")
|
||||||
return listener, nil
|
return listener, nil
|
||||||
//return g.Listen()
|
// return g.Listen()
|
||||||
}
|
}
|
||||||
|
|
||||||
// DialOnion returns a net.Conn for a onion structure's keys
|
// DialOnion returns a net.Conn for a onion structure's keys
|
||||||
|
@ -24,7 +24,7 @@ func TestBareOnion(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
log.Println("listener:", listener.Addr().String())
|
log.Println("listener:", listener.Addr().String())
|
||||||
//defer listener.Close()
|
// defer listener.Close()
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprintf(w, "Hello, %q", r.URL.Path)
|
fmt.Fprintf(w, "Hello, %q", r.URL.Path)
|
||||||
})
|
})
|
||||||
|
3
proxy.go
3
proxy.go
@ -1,10 +1,11 @@
|
|||||||
package onramp
|
package onramp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type OnrampProxy struct {
|
type OnrampProxy struct {
|
||||||
|
3
tls.go
3
tls.go
@ -10,7 +10,6 @@ import (
|
|||||||
"encoding/asn1"
|
"encoding/asn1"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
@ -18,6 +17,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/cretz/bine/torutil"
|
"github.com/cretz/bine/torutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user