cwtch/app/peer/bob/bob.go

41 lines
1.1 KiB
Go
Raw Normal View History

2018-10-04 19:15:03 +00:00
package main
import (
2019-01-04 21:44:21 +00:00
"cwtch.im/cwtch/event"
2018-10-04 19:15:03 +00:00
"cwtch.im/cwtch/peer"
2019-01-04 21:44:21 +00:00
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
2018-12-04 02:52:11 +00:00
"git.openprivacy.ca/openprivacy/libricochet-go/log"
2019-01-04 21:44:21 +00:00
"os"
"path"
2018-10-04 19:15:03 +00:00
"time"
)
func main() {
2019-01-04 21:44:21 +00:00
// System Boilerplate, We need Tor Up and Running
2018-12-04 02:52:11 +00:00
log.AddEverythingFromPattern("peer/bob")
2019-01-04 21:44:21 +00:00
log.SetLevel(log.LevelDebug)
acn, err := connectivity.StartTor(path.Join(".", ".cwtch"), "")
if err != nil {
log.Errorf("\nError connecting to Tor: %v\n", err)
os.Exit(1)
}
// Set up the Event Buss and Initialize the Peer
eventBus := event.NewEventManager()
2018-10-06 03:50:55 +00:00
bob := peer.NewCwtchPeer("bob")
2019-01-04 21:44:21 +00:00
bob.Init(acn, eventBus)
2018-10-04 19:15:03 +00:00
2019-01-04 21:44:21 +00:00
// Add Alice's Onion Here (It changes run to run)
bob.PeerWithOnion("upiztu7myymjf2dn4x4czhagp7axlnqjvf5zwfegbhtpkqb6v3vgu5yd")
2018-10-04 19:15:03 +00:00
2019-01-04 21:44:21 +00:00
// Send the Message...
2018-12-04 02:52:11 +00:00
log.Infof("Waiting for Bob to Connect to Alice...")
2019-01-04 21:44:21 +00:00
bob.SendMessageToPeer("upiztu7myymjf2dn4x4czhagp7axlnqjvf5zwfegbhtpkqb6v3vgu5yd", "Hello Alice!!!")
2018-10-04 19:15:03 +00:00
// Wait a while...
2019-01-04 21:44:21 +00:00
// Everything is run in a goroutine so the main thread has to stay active
2018-10-04 19:15:03 +00:00
time.Sleep(time.Second * 100)
}