Update README.md

Fixing the examples & adding removing untrue statements.
This commit is contained in:
Sarah Jamie Lewis 2017-11-02 16:15:12 -07:00 committed by GitHub
parent 3e6dc80670
commit 9d2e898157
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 34 deletions

View File

@ -15,47 +15,39 @@ Below is a simple echo bot, which responds to any chat message. You can also fin
package main package main
import ( import (
"github.com/s-rah/go-ricochet" "github.com/s-rah/go-ricochet/application"
"github.com/s-rah/go-ricochet/utils"
"log" "log"
"time"
) )
type EchoBotService struct {
goricochet.StandardRicochetService
}
// Always Accept Contact Requests
func (ts *EchoBotService) IsKnownContact(hostname string) bool {
return true
}
func (ts *EchoBotService) OnContactRequest(oc *goricochet.OpenConnection, channelID int32, nick string, message string) {
ts.StandardRicochetService.OnContactRequest(oc, channelID, nick, message)
oc.AckContactRequestOnResponse(channelID, "Accepted")
oc.CloseChannel(channelID)
}
func (ebs *EchoBotService) OnChatMessage(oc *goricochet.OpenConnection, channelID int32, messageId int32, message string) {
log.Printf("Received Message from %s: %s", oc.OtherHostname, message)
oc.AckChatMessage(channelID, messageId)
if oc.GetChannelType(6) == "none" {
oc.OpenChatChannel(6)
}
oc.SendMessage(6, message)
}
func main() { func main() {
ricochetService := new(EchoBotService) echobot := new(application.RicochetApplication)
ricochetService.Init("./private_key") pk, err := utils.LoadPrivateKeyFromFile("./private_key")
ricochetService.Listen(ricochetService, 12345)
if err != nil {
log.Fatalf("error reading private key file: %v", err)
}
l, err := application.SetupOnion("127.0.0.1:9051", "tcp4", "", pk, 9878)
if err != nil {
log.Fatalf("error setting up onion service: %v", err)
}
echobot.Init(pk, new(application.AcceptAllContactManager))
echobot.OnChatMessage(func(rai *application.RicochetApplicationInstance, id uint32, timestamp time.Time, message string) {
log.Printf("message from %v - %v", rai.RemoteHostname, message)
rai.SendChatMessage(message)
})
log.Printf("echobot listening on %s", l.Addr().String())
echobot.Run(l)
} }
Each automated ricochet service can extend of the `StandardRicochetService`. From there Each automated ricochet service can extend of the `StandardRicochetService`. From there
certain functions can be extended to fully build out a complete application. certain functions can be extended to fully build out a complete application.
Currently GoRicochet does not establish a hidden service, so to make this service
available to the world you will have to [set up a hidden service](https://www.torproject.org/docs/tor-hidden-service.html.en)
## Security and Usage Note ## Security and Usage Note
This project is experimental and has not been independently reviewed. If you are This project is experimental and has not been independently reviewed. If you are
looking for a quick and easy way to use ricochet please check out [Ricochet Protocol](https://ricochet.im). looking for a quick and easy way to use ricochet please check out [Ricochet IM](https://ricochet.im).