Skip to content
This repository has been archived by the owner on Dec 28, 2017. It is now read-only.

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Taylor committed Jun 12, 2012
0 parents commit a9d4079
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*~
*.tmp
*.out
6 changes: 6 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// emdr-relay-go project doc.go

/*
emdr-relay-go document
*/
package documentation
49 changes: 49 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package main

import (
"fmt"
zmq "github.com/alecthomas/gozmq"
"github.com/bradfitz/gomemcache/memcache"
"hash"
"hash/fnv"
)

func main() {
mc := memcache.New("127.0.0.1:11211")

context, _ := zmq.NewContext()

receiver, _ := context.NewSocket(zmq.SUB)
receiver.SetSockOptString(zmq.SUBSCRIBE, "")
receiver.Connect("tcp://relay-us-central-1.eve-emdr.com:8050")
//receiver.Connect("tcp://69.147.252.42:8050")

sender, _ := context.NewSocket(zmq.PUB)
sender.Bind("tcp://0.0.0.0:8050")

for {
msg, _ := receiver.Recv(0)

var h hash.Hash = fnv.New32()
h.Write(msg)

checksum := h.Sum([]byte{})
var checksum_str string = fmt.Sprintf("%x", checksum)

_, err := mc.Get(checksum_str)

mc.Set(&memcache.Item{Key: checksum_str, Value: []byte{1}, Expiration: 300})

if err == memcache.ErrCacheMiss {
sender.Send(msg, 0)
continue
}

if err == nil {
fmt.Printf("Dupe %x\n", checksum)
} else {
println("Some other error")
}

}
}

0 comments on commit a9d4079

Please sign in to comment.