Skip to content

Commit

Permalink
move java_home outside of OS switch since it is now OS agnostic. chan…
Browse files Browse the repository at this point in the history
…ged if statement to switch in p2pc
  • Loading branch information
jrhea committed Dec 3, 2018
1 parent 05f5a71 commit b56026c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ OS = $(shell uname -s | tr '[:upper:]' '[:lower:]')
ifeq ($(OS), linux)
EXT = so
OS_LFLAGS =
JAVA_HOME = $(shell java -XshowSettings:properties -version 2>&1 > /dev/null | grep 'java.home' | sed 's/\s*java.home = //')
else ifeq ($(OS), darwin)
EXT = dylib
OS_LFLAGS = -mmacosx-version-min=$(shell defaults read loginwindow SystemVersionStampAsString) -framework CoreFoundation -framework Security
JAVA_HOME = $(shell java -XshowSettings:properties -version 2>&1 > /dev/null | grep 'java.home' | sed 's/\s*java.home = //')
endif

CC = gcc
CFLAGS = -O2 -fPIC
LFLAGS = $(OS_LFLAGS) -shared

JAVA_HOME = $(shell java -XshowSettings:properties -version 2>&1 > /dev/null | grep 'java.home' | sed 's/\s*java.home = //')
JAVA_INCLUDES = -I$(JAVA_HOME)/include/$(OS) -I$(JAVA_HOME)/include
CLASS_PATH = .
vpath %.class $(CLASS_PATH)
Expand Down Expand Up @@ -46,13 +45,13 @@ go-%.a:
java-%.h:
cd $(JDIR) && javac -h $(CLASS_PATH) $*.java && mv $*.h $@

%.class: deps
%.class:
cd $(JDIR) && javac $*.java

go-client: deps
go-client:
cd $(CDIR) && go install ./...

go-daemon: deps
go-daemon:
cd $(DDIR) && go install ./...

deps: gx
Expand Down
37 changes: 31 additions & 6 deletions p2pc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ type ClientConfig struct {
args []string
}

type Command int

const (
Identify Command = 0
Connect Command = 1
ListenForMessage Command = 2
SendMessage Command = 3
)

func (c Command) String() string {
commands := [...]string{
"Identify",
"Connect",
"ListenForMessage",
"SendMessage",
}
return commands[c]
}

func main() {
identify.ClientVersion = "p2pc/0.1"
config := initialize()
Expand All @@ -49,20 +68,25 @@ func initialize() ClientConfig {
}

func start(config ClientConfig) {

client, err := p2pclient.NewClient(*config.pathd, *config.pathc)
defer os.Remove(*config.pathc)

if err != nil {
log.Fatal(err)
}

if *config.command == "Identify" {
switch *config.command {

case Identify.String():
id, addrs, err := client.Identify()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Daemon ID: %s\n", id.Pretty())
fmt.Printf("Peer addresses: %v\n", addrs)
} else if *config.command == "Connect" {

case Connect.String():
id, err := peer.IDB58Decode(config.args[0])
var addrs []multiaddr.Multiaddr
addrs = make([]multiaddr.Multiaddr, len(config.args[1:]))
Expand All @@ -78,7 +102,7 @@ func start(config ClientConfig) {
pi, err := client.FindPeer(id)
fmt.Printf("ID: %s has multiaddr: %v", pi.ID, pi.Addrs)

} else if *config.command == "ListenForMessage" {
case ListenForMessage.String():
protos := []string{"/test"}
done := make(chan struct{})
client.NewStreamHandler(protos, func(info *p2pclient.StreamInfo, conn io.ReadWriteCloser) {
Expand All @@ -92,7 +116,8 @@ func start(config ClientConfig) {
done <- struct{}{}
})
select {}
} else if *config.command == "SendMessage" {

case SendMessage.String():
protos := []string{"/test"}
recipientID, err := peer.IDB58Decode(config.args[0])
_, conn, err := client.NewStream(recipientID, protos)
Expand All @@ -104,9 +129,9 @@ func start(config ClientConfig) {
log.Fatal(err)
}

}
default:

os.Remove(*config.pathc)
}
}

//export startClient
Expand Down

0 comments on commit b56026c

Please sign in to comment.