Adding examples
This commit is contained in:
parent
64d08bdff0
commit
3469935bcb
|
@ -0,0 +1,30 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/s-rah/go-ricochet"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
ricochet := new(goricochet.Ricochet)
|
||||||
|
|
||||||
|
// You will want to replace these values with your own test credentials
|
||||||
|
ricochet.Init("./private_key", true)
|
||||||
|
ricochet.Connect("kwke2hntvyfqm7dr", "127.0.0.1:55555|jlq67qzo6s4yp3sp")
|
||||||
|
|
||||||
|
// Not needed passed the initial run
|
||||||
|
// TODO need to wait for contact response before sending OpenChannel
|
||||||
|
// ricochet.SendContactRequest("EchoBot", "I'm an EchoBot")
|
||||||
|
|
||||||
|
go ricochet.ListenAndWait()
|
||||||
|
ricochet.OpenChannel("im.ricochet.chat", 5)
|
||||||
|
ricochet.SendMessage("Hi I'm an echo bot, I echo what you say! ", 5)
|
||||||
|
|
||||||
|
for true {
|
||||||
|
message,channel,_ := ricochet.Listen()
|
||||||
|
fmt.Print(message, channel)
|
||||||
|
if message != "" {
|
||||||
|
ricochet.SendMessage(message, 5)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
13
ricochet.go
13
ricochet.go
|
@ -3,6 +3,7 @@ package goricochet
|
||||||
import (
|
import (
|
||||||
"crypto"
|
"crypto"
|
||||||
"crypto/hmac"
|
"crypto/hmac"
|
||||||
|
"crypto/rand"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
|
@ -17,6 +18,7 @@ import (
|
||||||
"github.com/s-rah/go-ricochet/contact"
|
"github.com/s-rah/go-ricochet/contact"
|
||||||
"github.com/s-rah/go-ricochet/control"
|
"github.com/s-rah/go-ricochet/control"
|
||||||
"h12.me/socks"
|
"h12.me/socks"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
@ -128,7 +130,11 @@ func (r *Ricochet) Connect(from string, to string) error {
|
||||||
ChannelIdentifier: proto.Int32(1),
|
ChannelIdentifier: proto.Int32(1),
|
||||||
ChannelType: proto.String("im.ricochet.auth.hidden-service"),
|
ChannelType: proto.String("im.ricochet.auth.hidden-service"),
|
||||||
}
|
}
|
||||||
err := proto.SetExtension(oc, Protocol_Data_AuthHiddenService.E_ClientCookie, []byte("0000000000000000"))
|
|
||||||
|
var cookie [16]byte
|
||||||
|
io.ReadFull(rand.Reader, cookie[:])
|
||||||
|
|
||||||
|
err := proto.SetExtension(oc, Protocol_Data_AuthHiddenService.E_ClientCookie, cookie[:])
|
||||||
pc := &Protocol_Data_Control.Packet{
|
pc := &Protocol_Data_Control.Packet{
|
||||||
OpenChannel: oc,
|
OpenChannel: oc,
|
||||||
}
|
}
|
||||||
|
@ -157,7 +163,7 @@ func (r *Ricochet) Connect(from string, to string) error {
|
||||||
r.logger.Print("Starting Authentication with Server Cookie: ", serverCookie)
|
r.logger.Print("Starting Authentication with Server Cookie: ", serverCookie)
|
||||||
|
|
||||||
key := make([]byte, 32)
|
key := make([]byte, 32)
|
||||||
copy(key[0:16], []byte("0000000000000000"))
|
copy(key[0:16], cookie[:])
|
||||||
copy(key[16:], serverCookie)
|
copy(key[16:], serverCookie)
|
||||||
value := []byte(from + to)
|
value := []byte(from + to)
|
||||||
r.logger.Print("Got Hmac Key: ", key)
|
r.logger.Print("Got Hmac Key: ", key)
|
||||||
|
@ -392,8 +398,11 @@ func (r *Ricochet) ListenAndWait() error {
|
||||||
r.logger.Print("Channel Opened Successfully: ", channelResult.GetChannelIdentifier())
|
r.logger.Print("Channel Opened Successfully: ", channelResult.GetChannelIdentifier())
|
||||||
r.channelState[int(message.ControlPacket.GetChannelResult().GetChannelIdentifier())] = 1
|
r.channelState[int(message.ControlPacket.GetChannelResult().GetChannelIdentifier())] = 1
|
||||||
}
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if packet.Channel == 3 {
|
||||||
|
// Contact Request
|
||||||
} else {
|
} else {
|
||||||
// At this point the only other expected type of message
|
// At this point the only other expected type of message
|
||||||
// is a Chat Message
|
// is a Chat Message
|
||||||
|
|
Loading…
Reference in New Issue