Official cwtch.im peer and server implementations. https://cwtch.im
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

alice.go 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package main
  2. import (
  3. "cwtch.im/cwtch/event"
  4. "cwtch.im/cwtch/peer"
  5. "git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
  6. "git.openprivacy.ca/openprivacy/libricochet-go/log"
  7. "os"
  8. "path"
  9. )
  10. func main() {
  11. // System Setup, We need Tor and Logging up and Running
  12. log.AddEverythingFromPattern("peer/alice")
  13. log.SetLevel(log.LevelDebug)
  14. acn, err := connectivity.StartTor(path.Join(".", ".cwtch"), "")
  15. if err != nil {
  16. log.Errorf("\nError connecting to Tor: %v\n", err)
  17. os.Exit(1)
  18. }
  19. // Setup the Event Bus to Listen for Data Packets
  20. eventBus := event.NewEventManager()
  21. queue := event.NewEventQueue(100)
  22. eventBus.Subscribe(event.NewMessageFromPeer, queue.EventChannel)
  23. // Setup Alice to Listen for new Events
  24. alice := peer.NewCwtchPeer("alice")
  25. alice.Init(acn, eventBus)
  26. alice.Listen()
  27. // For every new Data Packet Alice received she will Print it out.
  28. for {
  29. event := queue.Next()
  30. log.Printf(log.LevelInfo, "Received %v from %v: %s", event.EventType, event.Data["Onion"], event.Data["Data"])
  31. }
  32. }