Formatting + Checking Connection Error in Echobot

This commit is contained in:
Sarah Jamie Lewis 2017-11-02 16:43:11 -07:00
parent 9d2e898157
commit 5057dd68ee
4 changed files with 61 additions and 24 deletions

View File

@ -119,7 +119,7 @@ func (ra *RicochetApplication) handleConnection(conn net.Conn) {
rc.Process(rai)
}
func (ra *RicochetApplication) Shutdown () {
func (ra *RicochetApplication) Shutdown() {
log.Printf("Closing")
ra.l.Close()
log.Printf("Closed")

View File

@ -0,0 +1,32 @@
package main
import (
"github.com/s-rah/go-ricochet/application"
"github.com/s-rah/go-ricochet/utils"
"log"
"time"
)
func main() {
commandbot := new(application.RicochetApplication)
pk, err := utils.LoadPrivateKeyFromFile("./testing/private_key")
if err != nil {
log.Fatalf("error reading private key file: %v", err)
}
l, err := application.SetupOnion("127.0.0.1:9051", "", pk, 9878)
if err != nil {
log.Fatalf("error setting up onion service: %v", err)
}
commandbot.Init(pk, new(application.AcceptAllContactManager))
commandbot.OnChatMessage(func(rai *application.RicochetApplicationInstance, id uint32, timestamp time.Time, message string) {
if message == "/" {
rai.SendChatMessage(message)
}
})
log.Printf("commandbot listening on %s", l.Addr().String())
commandbot.Run(l)
}

View File

@ -53,7 +53,12 @@ func (echobot *RicochetEchoBot) Connect(privateKeyFile string, hostname string)
return chat
})
rc, _ := goricochet.Open(hostname)
rc, err := goricochet.Open(hostname)
if err != nil {
log.Fatalf("could not connect to %s: %v", hostname, err)
}
known, err := connection.HandleOutboundConnection(rc).ProcessAuthAsClient(privateKey)
if err == nil {
@ -61,7 +66,7 @@ func (echobot *RicochetEchoBot) Connect(privateKeyFile string, hostname string)
if !known {
err := rc.Do(func() error {
_,err := rc.RequestOpenChannel("im.ricochet.contact.request",
_, err := rc.RequestOpenChannel("im.ricochet.contact.request",
&channels.ContactRequestChannel{
Handler: echobot,
Name: "EchoBot",
@ -101,5 +106,5 @@ func (echobot *RicochetEchoBot) Connect(privateKeyFile string, hostname string)
func main() {
echoBot := new(RicochetEchoBot)
echoBot.Connect("private_key", "oqf7z4ot6kuejgam")
echoBot.Connect("private_key", "flkjmgvjloyyzlpe")
}

View File

@ -1,12 +1,12 @@
package utils
import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"io/ioutil"
"errors"
"crypto/rand"
"io/ioutil"
)
const (