tidying up code paths and making detport selection a little better

This commit is contained in:
erinn 2018-10-09 10:13:43 -07:00
parent b1738ac964
commit 9c1c5ef98a
4 changed files with 21 additions and 19 deletions

View File

@ -56,7 +56,7 @@ func main() {
log.Printf("Expected ID: %v", id) log.Printf("Expected ID: %v", id)
cfg := &bulb.NewOnionConfig{ cfg := &bulb.NewOnionConfig{
DiscardPK: true, DiscardPK: true,
PrivateKey: pk, PrivateKey: pk,
} }
l, err := c.NewListener(cfg, 80) l, err := c.NewListener(cfg, 80)

View File

@ -8,14 +8,15 @@
package bulb package bulb
import ( import (
"crypto"
goodrand "crypto/rand" goodrand "crypto/rand"
"encoding/binary"
"fmt" "fmt"
"net"
"strconv"
"golang.org/x/crypto/sha3" "golang.org/x/crypto/sha3"
"encoding/binary" "log"
"crypto" "net"
) "strconv"
)
type onionAddr struct { type onionAddr struct {
info *OnionInfo info *OnionInfo
@ -86,6 +87,7 @@ func (c *Conn) RecoverListener(config *NewOnionConfig, onion string, vports ...u
if port < 1024 { // this is not uniformly random, but we don't need it to be if port < 1024 { // this is not uniformly random, but we don't need it to be
port += 1024 port += 1024
} }
log.Printf("using local port: %d\n", port)
var loopbackAddr = "127.0.0.1:" + strconv.Itoa(port) var loopbackAddr = "127.0.0.1:" + strconv.Itoa(port)
// Listen on the loopback interface. // Listen on the loopback interface.

View File

@ -9,8 +9,8 @@ package bulb
import ( import (
"fmt" "fmt"
"strings"
"net/textproto" "net/textproto"
"strings"
) )
// The various control port StatusCode constants. // The various control port StatusCode constants.

View File

@ -18,19 +18,19 @@ import (
// SplitQuoted splits s by sep if it is found outside substring // SplitQuoted splits s by sep if it is found outside substring
// quoted by quote. // quoted by quote.
func SplitQuoted(s string, quote, sep rune) (splitted []string) { func SplitQuoted(s string, quote, sep rune) (splitted []string) {
quoteFlag := false quoteFlag := false
NewSubstring: NewSubstring:
for i, c := range s { for i, c := range s {
if c == quote { if c == quote {
quoteFlag = !quoteFlag quoteFlag = !quoteFlag
} }
if c == sep && !quoteFlag { if c == sep && !quoteFlag {
splitted = append(splitted, s[:i]) splitted = append(splitted, s[:i])
s = s[i+1:] s = s[i+1:]
goto NewSubstring goto NewSubstring
} }
} }
return append(splitted, s) return append(splitted, s)
} }
// ParseControlPortString parses a string representation of a control port // ParseControlPortString parses a string representation of a control port