Merge branch 'logging' of dan/cwtch into master
This commit is contained in:
commit
4a4c153103
|
@ -8,8 +8,8 @@ import (
|
|||
"fmt"
|
||||
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
@ -43,7 +43,7 @@ type Application interface {
|
|||
|
||||
// NewApp creates a new app with some environment awareness and initializes a Tor Manager
|
||||
func NewApp(acn connectivity.ACN, appDirectory string) Application {
|
||||
log.Printf("NewApp(%v)\n", appDirectory)
|
||||
log.Debugf("NewApp(%v)\n", appDirectory)
|
||||
app := &application{peers: make(map[string]peer.CwtchPeer), storage: make(map[string]storage.ProfileStore), directory: appDirectory, acn: acn}
|
||||
os.Mkdir(path.Join(app.directory, "profiles"), 0700)
|
||||
return app
|
||||
|
@ -64,7 +64,7 @@ func (app *application) SaveProfile(p peer.CwtchPeer) {
|
|||
|
||||
// NewProfile creates a new cwtchPeer with a given name.
|
||||
func (app *application) CreatePeer(name string, password string) (peer.CwtchPeer, error) {
|
||||
log.Printf("CreatePeer(%v)\n", name)
|
||||
log.Debugf("CreatePeer(%v)\n", name)
|
||||
|
||||
randomFileName := generateRandomFilename()
|
||||
fileStore := storage.CreateFileProfileStore(path.Join(app.directory, "profiles", randomFileName), password)
|
||||
|
@ -105,7 +105,7 @@ func (app *application) LoadProfiles(password string) error {
|
|||
_, exists := app.peers[p.GetProfile().Onion]
|
||||
if exists {
|
||||
p.Shutdown()
|
||||
log.Printf("Error: profile for onion %v already exists", p.GetProfile().Onion)
|
||||
log.Errorf("profile for onion %v already exists", p.GetProfile().Onion)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
@ -34,7 +32,6 @@ func waitForPeerServerConnection(peer peer.CwtchPeer, server string) error {
|
|||
}
|
||||
|
||||
func main() {
|
||||
log.SetOutput(ioutil.Discard)
|
||||
if len(os.Args) != 2 {
|
||||
fmt.Printf("Usage: ./servermon SERVER_ADDRESS\n")
|
||||
os.Exit(1)
|
||||
|
|
|
@ -9,9 +9,9 @@ import (
|
|||
"cwtch.im/cwtch/peer/connections"
|
||||
"fmt"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||
"github.com/c-bata/go-prompt"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
"log"
|
||||
"os"
|
||||
"os/user"
|
||||
"path"
|
||||
|
@ -247,21 +247,23 @@ func main() {
|
|||
@+''+@ '++@ ;++@ '#''@ ##'''@: +++, +++, :@ @@@@ @@@' @@@ '@@@
|
||||
:' ' '`
|
||||
fmt.Printf("%v\n\n", cwtch)
|
||||
|
||||
quit := false
|
||||
|
||||
usr, err := user.Current()
|
||||
if err != nil {
|
||||
log.Fatalf("\nError: could not load current user: %v\n", err)
|
||||
log.Errorf("\nError: could not load current user: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
acn, err := connectivity.StartTor(path.Join(usr.HomeDir, ".cwtch"), "")
|
||||
if err != nil {
|
||||
log.Fatalf("\nError connecting to Tor: %v\n", err)
|
||||
log.Errorf("\nError connecting to Tor: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
app = app2.NewApp(acn, path.Join(usr.HomeDir, ".cwtch"))
|
||||
if err != nil {
|
||||
log.Fatalf("Error initializing application: %v", err)
|
||||
log.Errorf("Error initializing application: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("\nWelcome to Cwtch!\n")
|
||||
fmt.Printf("If this if your first time you should create a profile by running `/new-profile`\n")
|
||||
|
|
|
@ -8,65 +8,66 @@ import (
|
|||
"fmt"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/utils"
|
||||
|
||||
"github.com/sethvargo/go-diceware/diceware"
|
||||
"errors"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||
"golang.org/x/crypto/ed25519"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func convertCwtchFile(filename string, password string) {
|
||||
func convertCwtchFile(filename string, password string) error {
|
||||
fileStore := storage2.CreateFileProfileStore(filename, password)
|
||||
peer, err := fileStore.Load()
|
||||
if err != nil {
|
||||
log.Fatalf("%v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
b := []byte("== ed25519v1-secret: type0 ==")
|
||||
b = append(b, peer.GetProfile().Ed25519PrivateKey...)
|
||||
err = ioutil.WriteFile("hs_ed25519_secret_key", b, 0600)
|
||||
if err != nil {
|
||||
log.Fatalf("%v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
b = []byte("== ed25519v1-public: type0 ==")
|
||||
b = append(b, peer.GetProfile().Ed25519PublicKey...)
|
||||
err = ioutil.WriteFile("hs_ed25519_public_key", b, 0600)
|
||||
if err != nil {
|
||||
log.Fatalf("%v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
b = []byte(peer.GetProfile().Onion + ".onion\n")
|
||||
err = ioutil.WriteFile("hostname", b, 0600)
|
||||
if err != nil {
|
||||
log.Fatalf("%v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println("success!")
|
||||
log.Infoln("success!")
|
||||
return nil
|
||||
}
|
||||
|
||||
func convertTorFile(filename string, password string) {
|
||||
log.Fatalf("this code doesn't work and can never work :( it's a math thing")
|
||||
func convertTorFile(filename string, password string) error {
|
||||
return errors.New("this code doesn't work and can never work :( it's a math thing")
|
||||
|
||||
name, _ := diceware.Generate(2)
|
||||
/*name, _ := diceware.Generate(2)
|
||||
sk, err := ioutil.ReadFile("hs_ed25519_secret_key")
|
||||
if err != nil {
|
||||
log.Fatalf("%v", err)
|
||||
return err
|
||||
}
|
||||
sk = sk[32:]
|
||||
|
||||
pk, err := ioutil.ReadFile("hs_ed25519_public_key")
|
||||
if err != nil {
|
||||
log.Fatalf("%v", err)
|
||||
return err
|
||||
}
|
||||
pk = pk[32:]
|
||||
|
||||
onion, err := ioutil.ReadFile("hostname")
|
||||
if err != nil {
|
||||
log.Fatalf("%v", err)
|
||||
return err
|
||||
}
|
||||
onion = onion[:56]
|
||||
|
||||
|
@ -79,13 +80,14 @@ func convertTorFile(filename string, password string) {
|
|||
fileStore := storage2.CreateFileProfileStore(filename, password)
|
||||
err = fileStore.Save(peer)
|
||||
if err != nil {
|
||||
log.Fatalf("%v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("success! loaded %d byte pk and %d byte sk for %s.onion\n", len(pk), len(sk), onion)
|
||||
log.Infof("success! loaded %d byte pk and %d byte sk for %s.onion\n", len(pk), len(sk), onion)
|
||||
return nil*/
|
||||
}
|
||||
|
||||
func vanity() {
|
||||
func vanity() error {
|
||||
for {
|
||||
pk, sk, err := ed25519.GenerateKey(rand.Reader)
|
||||
if err != nil {
|
||||
|
@ -101,19 +103,20 @@ func vanity() {
|
|||
fileStore := storage2.CreateFileProfileStore(os.Args[3], onion+".cwtch")
|
||||
err := fileStore.Save(peer)
|
||||
if err != nil {
|
||||
log.Fatalf("%v", err)
|
||||
return err
|
||||
}
|
||||
log.Printf("found %s.onion\n", onion)
|
||||
log.Infof("found %s.onion\n", onion)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func printHelp() {
|
||||
log.Println("usage: cwtchutil {help, convert-cwtch-file, convert-tor-file, changepw, vanity}")
|
||||
log.Infoln("usage: cwtchutil {help, convert-cwtch-file, convert-tor-file, changepw, vanity}")
|
||||
}
|
||||
|
||||
func main() {
|
||||
log.SetLevel(log.LevelInfo)
|
||||
if len(os.Args) < 2 {
|
||||
printHelp()
|
||||
os.Exit(1)
|
||||
|
@ -126,28 +129,34 @@ func main() {
|
|||
printHelp()
|
||||
case "convert-cwtch-file":
|
||||
if len(os.Args) != 4 {
|
||||
log.Println("example: cwtchutil convert-cwtch-file ~/.cwtch/profiles/11ddd78a9918c064e742d5e36a8b8fd4 passw0rd")
|
||||
fmt.Println("example: cwtchutil convert-cwtch-file ~/.cwtch/profiles/11ddd78a9918c064e742d5e36a8b8fd4 passw0rd")
|
||||
os.Exit(1)
|
||||
}
|
||||
convertCwtchFile(os.Args[2], os.Args[3])
|
||||
err := convertCwtchFile(os.Args[2], os.Args[3])
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
}
|
||||
case "convert-tor-file":
|
||||
if len(os.Args) != 4 {
|
||||
log.Println("example: cwtchutil convert-tor-file /var/lib/tor/hs1 passw0rd")
|
||||
fmt.Println("example: cwtchutil convert-tor-file /var/lib/tor/hs1 passw0rd")
|
||||
os.Exit(1)
|
||||
}
|
||||
convertTorFile(os.Args[2], os.Args[3])
|
||||
err := convertTorFile(os.Args[2], os.Args[3])
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
}
|
||||
case "vanity":
|
||||
if len(os.Args) < 5 {
|
||||
log.Println("example: cwtchutil vanity 4 passw0rd erinn openpriv")
|
||||
fmt.Println("example: cwtchutil vanity 4 passw0rd erinn openpriv")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
goroutines, err := strconv.Atoi(os.Args[2])
|
||||
if err != nil {
|
||||
log.Printf("first parameter after vanity should be a number\n")
|
||||
log.Errorf("first parameter after vanity should be a number\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
log.Println("searching. press ctrl+c to stop")
|
||||
log.Infoln("searching. press ctrl+c to stop")
|
||||
for i := 0; i < goroutines; i++ {
|
||||
go vanity()
|
||||
}
|
||||
|
@ -157,14 +166,16 @@ func main() {
|
|||
}
|
||||
case "changepw":
|
||||
if len(os.Args) != 3 {
|
||||
log.Fatalf("example: cwtch changepw ~/.cwtch/profiles/XXX")
|
||||
fmt.Println("example: cwtch changepw ~/.cwtch/profiles/XXX")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("old password: ")
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
pw, err := reader.ReadString('\n')
|
||||
if err != nil {
|
||||
log.Fatalf("%v", err)
|
||||
log.Errorln(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
pw = pw[:len(pw)-1]
|
||||
|
||||
|
@ -172,23 +183,25 @@ func main() {
|
|||
|
||||
peer, err := fileStore.Load()
|
||||
if err != nil {
|
||||
log.Fatalf("%v", err)
|
||||
log.Errorln(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("new password: ")
|
||||
newpw1, err := reader.ReadString('\n')
|
||||
if err != nil {
|
||||
log.Fatalf("%v", err)
|
||||
log.Errorln(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
newpw1 = newpw1[:len(newpw1)-1] // fuck go with this linebreak shit ^ea
|
||||
|
||||
fileStore2 := storage2.CreateFileProfileStore(os.Args[2], newpw1)
|
||||
err = fileStore2.Save(peer)
|
||||
if err != nil {
|
||||
log.Fatalf("%v", err)
|
||||
log.Errorln(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
log.Println("success!")
|
||||
|
||||
log.Infoln("success!")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,17 +2,19 @@ package main
|
|||
|
||||
import (
|
||||
"cwtch.im/cwtch/peer"
|
||||
"log"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.AddEverythingFromPattern("peer/alice")
|
||||
alice := peer.NewCwtchPeer("alice")
|
||||
|
||||
processData := func(onion string, data []byte) []byte {
|
||||
log.Printf("Recieved %s from %v", data, onion)
|
||||
log.Debugf("Recieved %s from %v", data, onion)
|
||||
return data
|
||||
}
|
||||
|
||||
alice.SetPeerDataHandler(processData)
|
||||
alice.Listen()
|
||||
|
||||
}
|
||||
|
|
|
@ -2,23 +2,24 @@ package main
|
|||
|
||||
import (
|
||||
"cwtch.im/cwtch/peer"
|
||||
"log"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.AddEverythingFromPattern("peer/bob")
|
||||
bob := peer.NewCwtchPeer("bob")
|
||||
counter := 1
|
||||
|
||||
bob.SetPeerDataHandler(func(onion string, data []byte) []byte {
|
||||
log.Printf("Recieved %s from %v", data, onion)
|
||||
log.Infof("Recieved %s from %v", data, onion)
|
||||
counter++
|
||||
return []byte(strconv.Itoa(counter))
|
||||
})
|
||||
connection := bob.PeerWithOnion("f4b6thuwmfszsqd3fzqpr45sdem4qoazdlzr2xmnc7fq22qe746hjqqd")
|
||||
|
||||
log.Printf("Waiting for Bob to Connect to Alice...")
|
||||
log.Infof("Waiting for Bob to Connect to Alice...")
|
||||
connection.SendPacket([]byte("Hello Alice!!!"))
|
||||
|
||||
// Wait a while...
|
||||
|
|
|
@ -5,11 +5,11 @@ import (
|
|||
"cwtch.im/cwtch/protocol"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/utils"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"golang.org/x/crypto/nacl/secretbox"
|
||||
"io"
|
||||
"log"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
@ -43,14 +43,14 @@ func NewGroup(server string) (*Group, error) {
|
|||
|
||||
var groupID [16]byte
|
||||
if _, err := io.ReadFull(rand.Reader, groupID[:]); err != nil {
|
||||
log.Printf("Error: Cannot read from random: %v\n", err)
|
||||
log.Errorf("Cannot read from random: %v\n", err)
|
||||
return nil, err
|
||||
}
|
||||
group.GroupID = fmt.Sprintf("%x", groupID)
|
||||
|
||||
var groupKey [32]byte
|
||||
if _, err := io.ReadFull(rand.Reader, groupKey[:]); err != nil {
|
||||
log.Printf("Error: Cannot read from random: %v\n", err)
|
||||
log.Errorf("Error: Cannot read from random: %v\n", err)
|
||||
return nil, err
|
||||
}
|
||||
copy(group.GroupKey[:], groupKey[:])
|
||||
|
@ -135,7 +135,7 @@ func (g *Group) GetTimeline() (t []Message) {
|
|||
func (g *Group) EncryptMessage(message *protocol.DecryptedGroupMessage) ([]byte, error) {
|
||||
var nonce [24]byte
|
||||
if _, err := io.ReadFull(rand.Reader, nonce[:]); err != nil {
|
||||
log.Printf("Error: Cannot read from random: %v\n", err)
|
||||
log.Errorf("Cannot read from random: %v\n", err)
|
||||
return nil, err
|
||||
}
|
||||
wire, err := proto.Marshal(message)
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"git.openprivacy.ca/openprivacy/libricochet-go/connection"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/identity"
|
||||
"log"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -61,7 +61,7 @@ func (ppc *PeerPeerConnection) SendPacket(data []byte) {
|
|||
if channel != nil {
|
||||
peerchannel, ok := channel.Handler.(*peer.CwtchPeerDataChannel)
|
||||
if ok {
|
||||
log.Printf("Sending packet\n")
|
||||
log.Debugf("Sending packet\n")
|
||||
peerchannel.SendMessage(data)
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ func (ppc *PeerPeerConnection) SendGroupInvite(invite []byte) {
|
|||
if channel != nil {
|
||||
peerchannel, ok := channel.Handler.(*peer.CwtchPeerChannel)
|
||||
if ok {
|
||||
log.Printf("Sending group invite packet\n")
|
||||
log.Debugf("Sending group invite packet\n")
|
||||
peerchannel.SendMessage(invite)
|
||||
}
|
||||
}
|
||||
|
@ -112,7 +112,6 @@ func (ppc *PeerPeerConnection) Run() error {
|
|||
ppc.state = CONNECTING
|
||||
rc, err := goricochet.Open(ppc.acn, ppc.PeerHostname)
|
||||
if err == nil {
|
||||
rc.TraceLog(false)
|
||||
ppc.connection = rc
|
||||
ppc.state = CONNECTED
|
||||
_, err := connection.HandleOutboundConnection(ppc.connection).ProcessAuthAsV3Client(identity.InitializeV3(ppc.profile.Name, &ppc.profile.Ed25519PrivateKey, &ppc.profile.Ed25519PublicKey))
|
||||
|
|
|
@ -32,7 +32,6 @@ func runtestpeer(t *testing.T, tp *TestPeer, identity identity.Identity, listenC
|
|||
if err != nil {
|
||||
t.Errorf("Negotiate Version Error: %v", err)
|
||||
}
|
||||
rc.TraceLog(true)
|
||||
err = connection.HandleInboundConnection(rc).ProcessAuthAsV3Server(identity, PeerAuthValid)
|
||||
if err != nil {
|
||||
t.Errorf("ServerAuth Error: %v", err)
|
||||
|
|
|
@ -12,8 +12,8 @@ import (
|
|||
"git.openprivacy.ca/openprivacy/libricochet-go/connection"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/identity"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||
"golang.org/x/crypto/ed25519"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -54,10 +54,9 @@ func (psc *PeerServerConnection) WaitTilAuthenticated() {
|
|||
|
||||
// Run manages the setup and teardown of a peer server connection
|
||||
func (psc *PeerServerConnection) Run() error {
|
||||
log.Printf("Connecting to %v", psc.Server)
|
||||
log.Infof("Connecting to %v", psc.Server)
|
||||
rc, err := goricochet.Open(psc.acn, psc.Server)
|
||||
if err == nil {
|
||||
rc.TraceLog(true)
|
||||
psc.connection = rc
|
||||
psc.state = CONNECTED
|
||||
pub, priv, err := ed25519.GenerateKey(rand.Reader)
|
||||
|
@ -136,6 +135,6 @@ func (psc *PeerServerConnection) Close() {
|
|||
|
||||
// HandleGroupMessage passes the given group message back to the profile.
|
||||
func (psc *PeerServerConnection) HandleGroupMessage(gm *protocol.GroupMessage) {
|
||||
log.Printf("Received Group Message")
|
||||
log.Debugf("Received Group Message")
|
||||
psc.GroupMessageHandler(psc.Server, gm)
|
||||
}
|
||||
|
|
|
@ -43,7 +43,6 @@ func runtestserver(t *testing.T, ts *TestServer, identity identity.Identity, lis
|
|||
if err != nil {
|
||||
t.Errorf("Negotiate Version Error: %v", err)
|
||||
}
|
||||
rc.TraceLog(true)
|
||||
err = connection.HandleInboundConnection(rc).ProcessAuthAsV3Server(identity, ServerAuthValid)
|
||||
if err != nil {
|
||||
t.Errorf("ServerAuth Error: %v", err)
|
||||
|
|
|
@ -14,10 +14,10 @@ import (
|
|||
"git.openprivacy.ca/openprivacy/libricochet-go/connection"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/identity"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/utils"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"golang.org/x/crypto/ed25519"
|
||||
"log"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -195,7 +195,7 @@ func (cp *cwtchPeer) InviteOnionToGroup(onion string, groupid string) error {
|
|||
|
||||
group := cp.Profile.GetGroupByGroupID(groupid)
|
||||
if group != nil {
|
||||
log.Printf("Constructing invite for group: %v\n", group)
|
||||
log.Infof("Constructing invite for group: %v\n", group)
|
||||
invite, err := group.Invite(group.GetInitialMessage())
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -205,7 +205,7 @@ func (cp *cwtchPeer) InviteOnionToGroup(onion string, groupid string) error {
|
|||
return errors.New("peer connection not setup for onion. peers must be trusted before sending")
|
||||
}
|
||||
if ppc.GetState() == connections.AUTHENTICATED {
|
||||
log.Printf("Got connection for group: %v - Sending Invite\n", ppc)
|
||||
log.Infof("Got connection for group: %v - Sending Invite\n", ppc)
|
||||
ppc.SendGroupInvite(invite)
|
||||
} else {
|
||||
return errors.New("cannot send invite to onion: peer connection is not ready")
|
||||
|
@ -352,7 +352,7 @@ func (cp *cwtchPeer) listenFn() error {
|
|||
}
|
||||
|
||||
ra.Init(cp.acn, cp.Profile.Name, identity.InitializeV3(cp.Profile.Name, &cp.Profile.Ed25519PrivateKey, &cp.Profile.Ed25519PublicKey), af, cp)
|
||||
log.Printf("Running cwtch peer on %v", onionService.AddressFull())
|
||||
log.Infof("Running cwtch peer on %v", onionService.AddressFull())
|
||||
cp.app = ra
|
||||
cp.started = true
|
||||
ra.Run(onionService)
|
||||
|
@ -395,7 +395,7 @@ type CwtchPeerHandler struct {
|
|||
|
||||
// HandleGroupInvite handles incoming GroupInvites
|
||||
func (cph *CwtchPeerHandler) HandleGroupInvite(gci *protocol.GroupChatInvite) {
|
||||
log.Printf("Received GroupID from %v %v\n", cph.Onion, gci.String())
|
||||
log.Debugf("Received GroupID from %v %v\n", cph.Onion, gci.String())
|
||||
cph.Peer.Profile.ProcessInvite(gci, cph.Onion)
|
||||
}
|
||||
|
||||
|
|
|
@ -3,10 +3,10 @@ package peer
|
|||
import (
|
||||
"cwtch.im/cwtch/protocol"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/channels"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/utils"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/wire/control"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"log"
|
||||
)
|
||||
|
||||
// CwtchPeerChannel implements the ChannelHandler interface for a channel of
|
||||
|
@ -101,6 +101,6 @@ func (cpc *CwtchPeerChannel) Packet(data []byte) {
|
|||
cpc.Handler.HandleGroupInvite(cpp.GetGroupChatInvite())
|
||||
}
|
||||
} else {
|
||||
log.Printf("Error Receivng Packet %v\n", err)
|
||||
log.Errorf("Error Receivng Packet %v\n", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
cwtchserver "cwtch.im/cwtch/server"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
|
||||
"log"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
@ -13,18 +13,21 @@ const (
|
|||
)
|
||||
|
||||
func main() {
|
||||
log.AddEverythingFromPattern("server/app/main")
|
||||
log.AddEverythingFromPattern("server/server")
|
||||
configDir := os.Getenv("CWTCH_CONFIG_DIR")
|
||||
|
||||
serverConfig := cwtchserver.LoadConfig(configDir, serverConfigFile)
|
||||
|
||||
acn, err := connectivity.StartTor(path.Join(configDir, "tor"), "")
|
||||
if err != nil {
|
||||
log.Fatalf("\nError connecting to Tor: %v\n", err)
|
||||
log.Errorf("\nError connecting to Tor: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer acn.Close()
|
||||
|
||||
server := new(cwtchserver.Server)
|
||||
log.Printf("starting cwtch server...")
|
||||
log.Infoln("starting cwtch server...")
|
||||
|
||||
// TODO load params from .cwtch/server.conf or command line flag
|
||||
// TODO: respond to HUP so t.Close is gracefully called
|
||||
|
|
|
@ -4,8 +4,8 @@ import (
|
|||
"bufio"
|
||||
"fmt"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/application"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||
"github.com/struCoder/pidusage"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"time"
|
||||
|
@ -59,7 +59,7 @@ func (mp *Monitors) run() {
|
|||
func (mp *Monitors) report() {
|
||||
f, err := os.Create(path.Join(mp.configDir, reportFile))
|
||||
if err != nil {
|
||||
log.Println("ERROR: Could not open monitor reporting file: ", err)
|
||||
log.Errorf("Could not open monitor reporting file: ", err)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
|
|
@ -5,9 +5,9 @@ import (
|
|||
"cwtch.im/cwtch/protocol/spam"
|
||||
"errors"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/channels"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/wire/control"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"log"
|
||||
)
|
||||
|
||||
// CwtchServerSendChannel implements the ChannelHandler interface for a channel of
|
||||
|
@ -89,11 +89,11 @@ func (cc *CwtchServerSendChannel) Packet(data []byte) {
|
|||
if ok {
|
||||
cc.Handler.HandleGroupMessage(gm)
|
||||
} else {
|
||||
log.Printf("[ERROR] Failed to validate spamguard %v\n", gm)
|
||||
log.Errorf("Failed to validate spamguard %v\n", gm)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.Printf("[ERROR] Failed to decode packet on SEND channel %v\n", err)
|
||||
log.Errorf("Failed to decode packet on SEND channel %v\n", err)
|
||||
}
|
||||
cc.channel.CloseChannel()
|
||||
}
|
||||
|
|
|
@ -11,7 +11,8 @@ import (
|
|||
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/utils"
|
||||
|
||||
"log"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
@ -37,7 +38,9 @@ func (s *Server) Run(acn connectivity.ACN, serverConfig Config) {
|
|||
ms := new(storage.MessageStore)
|
||||
err := ms.Init(serverConfig.ConfigDir, s.config.MaxBufferLines, s.metricsPack.MessageCounter)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Errorln(err)
|
||||
acn.Close()
|
||||
os.Exit(1)
|
||||
}
|
||||
af.AddHandler("im.cwtch.server.listen", func(rai *application.ApplicationInstance) func() channels.Handler {
|
||||
return func() channels.Handler {
|
||||
|
@ -69,14 +72,14 @@ func (s *Server) Run(acn connectivity.ACN, serverConfig Config) {
|
|||
addressIdentity := utils.GetTorV3Hostname(s.config.PublicKey)
|
||||
cwtchserver.Init(acn, "cwtch server for "+addressIdentity, s.config.Identity(), af, new(application.AcceptAllContactManager))
|
||||
port := strconv.Itoa(application.RicochetPort)
|
||||
log.Printf("cwtch server running on cwtch:%s", addressIdentity+".onion:"+port)
|
||||
log.Infof("cwtch server running on cwtch:%s\n", addressIdentity+".onion:"+port)
|
||||
|
||||
s.app = cwtchserver
|
||||
|
||||
for true {
|
||||
listenService, err := acn.Listen(s.config.PrivateKey, application.RicochetPort)
|
||||
if err != nil {
|
||||
log.Printf("Listen() error setting up onion service: %v\n", err)
|
||||
log.Errorf("Listen() error setting up onion service: %v\n", err)
|
||||
} else {
|
||||
s.app.Run(listenService)
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@ import (
|
|||
"crypto/rand"
|
||||
"encoding/json"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/identity"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||
"golang.org/x/crypto/ed25519"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"path"
|
||||
)
|
||||
|
||||
|
@ -33,14 +33,14 @@ func (config *Config) Identity() identity.Identity {
|
|||
|
||||
// Save dumps the latest version of the config to a json file given by filename
|
||||
func (config *Config) Save(dir, filename string) {
|
||||
log.Printf("Saving config to %s\n", path.Join(dir, filename))
|
||||
log.Infof("Saving config to %s\n", path.Join(dir, filename))
|
||||
bytes, _ := json.MarshalIndent(config, "", "\t")
|
||||
ioutil.WriteFile(path.Join(dir, filename), bytes, 0600)
|
||||
}
|
||||
|
||||
// LoadConfig loads a Config from a json file specified by filename
|
||||
func LoadConfig(configDir, filename string) Config {
|
||||
log.Printf("Loading config from %s\n", path.Join(configDir, filename))
|
||||
log.Infof("Loading config from %s\n", path.Join(configDir, filename))
|
||||
config := Config{}
|
||||
config.ConfigDir = configDir
|
||||
config.MaxBufferLines = 100000
|
||||
|
@ -50,7 +50,7 @@ func LoadConfig(configDir, filename string) Config {
|
|||
err = json.Unmarshal(raw, &config)
|
||||
|
||||
if err != nil {
|
||||
log.Println("Error reading config: ", err)
|
||||
log.Errorf("reading config: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,12 +6,12 @@ import (
|
|||
"cwtch.im/cwtch/peer"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||
"golang.org/x/crypto/nacl/secretbox"
|
||||
"golang.org/x/crypto/pbkdf2"
|
||||
"golang.org/x/crypto/sha3"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
)
|
||||
|
||||
// fileProfileStore stores a cwtchPeer in an encrypted file
|
||||
|
@ -48,7 +48,7 @@ func (fps *fileProfileStore) Save(cwtchPeer peer.CwtchPeer) error {
|
|||
func createKey(password string) ([32]byte, [128]byte, error) {
|
||||
var salt [128]byte
|
||||
if _, err := io.ReadFull(rand.Reader, salt[:]); err != nil {
|
||||
log.Printf("Error: Cannot read from random: %v\n", err)
|
||||
log.Errorf("Cannot read from random: %v\n", err)
|
||||
return [32]byte{}, salt, err
|
||||
}
|
||||
dk := pbkdf2.Key([]byte(password), salt[:], 4096, 32, sha3.New512)
|
||||
|
@ -63,7 +63,7 @@ func encryptProfile(p peer.CwtchPeer, key [32]byte) ([]byte, error) {
|
|||
var nonce [24]byte
|
||||
|
||||
if _, err := io.ReadFull(rand.Reader, nonce[:]); err != nil {
|
||||
log.Printf("Error: Cannot read from random: %v\n", err)
|
||||
log.Errorf("Cannot read from random: %v\n", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"cwtch.im/cwtch/server/metrics"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||
"os"
|
||||
"path"
|
||||
"sync"
|
||||
|
@ -61,7 +61,7 @@ func (ms *MessageStore) initAndLoadFiles() error {
|
|||
filename := path.Join(ms.storeDirectory, fmt.Sprintf("%s.%d", fileStoreFilename, i))
|
||||
f, err := os.OpenFile(filename, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0600)
|
||||
if err != nil {
|
||||
log.Printf("Error: MessageStore could not open: %v: %v", filename, err)
|
||||
log.Errorf("MessageStore could not open: %v: %v", filename, err)
|
||||
continue
|
||||
}
|
||||
ms.activeLogFile = f
|
||||
|
@ -86,7 +86,7 @@ func (ms *MessageStore) initAndLoadFiles() error {
|
|||
func (ms *MessageStore) updateFile(gm *protocol.GroupMessage) {
|
||||
s, err := json.Marshal(gm)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] Failed to unmarshal group message %v\n", err)
|
||||
log.Errorf("Failed to unmarshal group message %v\n", err)
|
||||
}
|
||||
fmt.Fprintf(ms.activeLogFile, "%s\n", s)
|
||||
ms.filePos++
|
||||
|
@ -105,7 +105,7 @@ func (ms *MessageStore) rotateFileStore() {
|
|||
|
||||
f, err := os.OpenFile(path.Join(ms.storeDirectory, fmt.Sprintf("%s.%d", fileStoreFilename, 0)), os.O_CREATE|os.O_APPEND|os.O_RDWR, 0600)
|
||||
if err != nil {
|
||||
log.Printf("ERROR: Could not open new message store file in: %s", ms.storeDirectory)
|
||||
log.Errorf("Could not open new message store file in: %s", ms.storeDirectory)
|
||||
}
|
||||
ms.filePos = 0
|
||||
ms.activeLogFile = f
|
||||
|
|
|
@ -8,8 +8,6 @@ import (
|
|||
"fmt"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
|
||||
"golang.org/x/net/proxy"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
@ -98,7 +96,6 @@ func waitForPeerPeerConnection(t *testing.T, peera peer.CwtchPeer, peerb peer.Cw
|
|||
|
||||
func TestCwtchPeerIntegration(t *testing.T) {
|
||||
// Hide logging "noise"
|
||||
log.SetOutput(ioutil.Discard)
|
||||
numGoRoutinesStart := runtime.NumGoroutine()
|
||||
|
||||
acn, err := connectivity.StartTor(".", "")
|
||||
|
|
Loading…
Reference in New Issue