Skip to content

Commit 8c5218c

Browse files
committed
first commit
0 parents  commit 8c5218c

File tree

7 files changed

+431
-0
lines changed

7 files changed

+431
-0
lines changed

Gopkg.lock

Lines changed: 174 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Gopkg.toml example
2+
#
3+
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
4+
# for detailed Gopkg.toml documentation.
5+
#
6+
# required = ["github.com/user/thing/cmd/thing"]
7+
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
8+
#
9+
# [[constraint]]
10+
# name = "github.com/user/project"
11+
# version = "1.0.0"
12+
#
13+
# [[constraint]]
14+
# name = "github.com/user/project2"
15+
# branch = "dev"
16+
# source = "github.com/myfork/project2"
17+
#
18+
# [[override]]
19+
# name = "github.com/x/y"
20+
# version = "2.4.0"
21+
#
22+
# [prune]
23+
# non-go = false
24+
# go-tests = true
25+
# unused-packages = true
26+
27+
28+
[[constraint]]
29+
revision = "af28d12847c4572c7c3d9f5775db9b18bcfc3889"
30+
name = "github.com/ethereum/go-ethereum"
31+
32+
[prune]
33+
go-tests = true

LICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <https://unlicense.org>

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# pchat: whisper-chat-example
2+
3+
## Running the example
4+
5+
The example assumes that there is a running Whisper v6 node exposing an RPC interface at URL `http://localhost:8545`. For this, you can use `geth` with the folloing parameters:
6+
7+
$ geth <usual p2p flags> --shh --rpc
8+
9+
10+
`--shh` is the option that enables Whisper v6 for the node.
11+
12+
`--rpc` enables the HTTP RPC interface.
13+
14+
## Download
15+
16+
download your version from [here](https://github.com/mabdalrahman/pchat/releases/tag/v1.0.0-alpha1)
17+
18+
## Installation From Source
19+
`pchat` requires Go 1.10.2 or later, [dep](github.com/golang/dep) to managing dependency package and [xgo](https://github.com/karalabe/xgo) for cross compile.
20+
21+
```
22+
$ go get -u github.com/mabdalrahman/pchat
23+
```
24+
25+
## Usage
26+
```
27+
pchat -username "user"
28+
29+
mandatory argument:
30+
-username set your username
31+
32+
optional arguments:
33+
-privatekey set your private key
34+
35+
```

cmd.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
)
7+
8+
var (
9+
// Username ...
10+
Username string
11+
// PrivateKey ...
12+
PrivateKey string
13+
)
14+
15+
// CheckArgs ...
16+
func CheckArgs() {
17+
// check if username is empty
18+
if Username == "" {
19+
msg := "Note:\n\tThis app is experimental, I'm just playing with a whisper protocol.\n"
20+
msg += "\tRun first go-ethereum 'geth --testnet --nodiscover --shh --rpc'\n"
21+
msg += "\tRun 'pchat --help' for more flags information.\n\n"
22+
msg += "USAGE:\n\tpchat -username [argument] [flag option] [argument]\n\n"
23+
fmt.Fprintln(os.Stderr, msg)
24+
os.Exit(1)
25+
}
26+
}

main.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"flag"
6+
"fmt"
7+
"log"
8+
"os"
9+
"strings"
10+
11+
"github.com/ethereum/go-ethereum/common/hexutil"
12+
)
13+
14+
func init() {
15+
//flags
16+
flag.StringVar(&Username, "username", "", "set username, example 'pchat -username \"user\"'")
17+
flag.StringVar(&PrivateKey, "privatekey", "", "set your private key")
18+
}
19+
20+
func main() {
21+
flag.Parse()
22+
CheckArgs()
23+
24+
ctx, c, id := Wconfig()
25+
fID := Receive(ctx, c, id)
26+
27+
var pubKey, msg string
28+
reader := bufio.NewReader(os.Stdin)
29+
30+
prKey, err := c.PrivateKey(ctx, id)
31+
if err != nil {
32+
log.Fatalln(err)
33+
}
34+
35+
fmt.Print("**********************************************************\n")
36+
fmt.Println("Your Private Key:", hexutil.Encode(prKey))
37+
38+
puKey, err := c.PublicKey(ctx, id)
39+
if err != nil {
40+
log.Fatalln(err)
41+
}
42+
fmt.Println("Your Public Key:", hexutil.Encode(puKey))
43+
fmt.Print("**********************************************************\n\n")
44+
45+
fmt.Print("Enter your partner public key: ")
46+
pubKey, _ = reader.ReadString('\n')
47+
48+
// receive message
49+
receivedMsg := make(chan string)
50+
go func(chan string) {
51+
for {
52+
m, err := c.FilterMessages(ctx, fID)
53+
if err != nil {
54+
log.Fatalln(err)
55+
}
56+
57+
if len(m) > 0 {
58+
receivedMsg <- fmt.Sprint(string(m[0].Padding)+": ", string(m[0].Payload))
59+
}
60+
}
61+
}(receivedMsg)
62+
63+
// send message
64+
go func() {
65+
for {
66+
msg, _ = reader.ReadString('\n')
67+
msg = strings.TrimSpace(msg)
68+
69+
if msg != "" {
70+
Post(ctx, c, Username, msg, strings.TrimSpace(pubKey))
71+
msg = ""
72+
}
73+
}
74+
}()
75+
76+
for {
77+
select {
78+
case m := <-receivedMsg:
79+
fmt.Println(m)
80+
default:
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)