Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-pubsub
Commits
c0d5b0ef
Commit
c0d5b0ef
authored
Sep 10, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
using protobuf now, with a vengeance
parent
6ed3d545
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
49 deletions
+35
-49
.gx/lastpubver
.gx/lastpubver
+1
-1
floodsub.go
floodsub.go
+17
-11
floodsub_test.go
floodsub_test.go
+2
-4
notify.go
notify.go
+2
-2
package.json
package.json
+7
-1
pb/rpc.pb.go
pb/rpc.pb.go
+6
-30
No files found.
.gx/lastpubver
View file @
c0d5b0ef
0.
1
.0: Qm
UvA4goPKAHLrTcePzzCDHqCpqtzdKAVdMPdrdw45Z2FM
0.
2
.0: Qm
TP5RSsmZacEFanuBhnDE3RC3aqGAoozF9ZmKqcHa8EKH
floodsub.go
View file @
c0d5b0ef
package
floodsub
import
(
"bufio"
"fmt"
"sync"
"sync/atomic"
"time"
pb
"github.com/whyrusleeping/go-floodsub/pb"
ggio
"github.com/gogo/protobuf/io"
proto
"github.com/gogo/protobuf/proto"
logging
"gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log
"
peer
"gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer
"
host
"g
x/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS
/go-libp2p/p2p/host"
inet
"g
x/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS
/go-libp2p/p2p/net"
protocol
"g
x/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS
/go-libp2p/p2p/protocol"
peer
"github.com/ipfs/go-libp2p-peer
"
logging
"github.com/ipfs/go-log
"
host
"g
ithub.com/libp2p
/go-libp2p/p2p/host"
inet
"g
ithub.com/libp2p
/go-libp2p/p2p/net"
protocol
"g
ithub.com/libp2p
/go-libp2p/p2p/protocol"
)
var
messageCount
uint64
const
ID
=
protocol
.
ID
(
"/floodsub/1.0.0"
)
var
(
...
...
@@ -113,15 +111,14 @@ func (p *PubSub) handleNewStream(s inet.Stream) {
func
(
p
*
PubSub
)
handleSendingMessages
(
s
inet
.
Stream
,
in
<-
chan
*
RPC
)
{
var
dead
bool
wc
:=
ggio
.
NewDelimitedWriter
(
s
)
bufw
:=
bufio
.
NewWriter
(
s
)
wc
:=
ggio
.
NewDelimitedWriter
(
bufw
)
defer
wc
.
Close
()
for
rpc
:=
range
in
{
if
dead
{
continue
}
atomic
.
AddUint64
(
&
messageCount
,
1
)
err
:=
wc
.
WriteMsg
(
&
rpc
.
RPC
)
if
err
!=
nil
{
log
.
Errorf
(
"writing message to %s: %s"
,
s
.
Conn
()
.
RemotePeer
(),
err
)
...
...
@@ -130,6 +127,15 @@ func (p *PubSub) handleSendingMessages(s inet.Stream, in <-chan *RPC) {
p
.
peerDead
<-
s
.
Conn
()
.
RemotePeer
()
}()
}
err
=
bufw
.
Flush
()
if
err
!=
nil
{
log
.
Errorf
(
"writing message to %s: %s"
,
s
.
Conn
()
.
RemotePeer
(),
err
)
dead
=
true
go
func
()
{
p
.
peerDead
<-
s
.
Conn
()
.
RemotePeer
()
}()
}
}
}
...
...
floodsub_test.go
View file @
c0d5b0ef
...
...
@@ -8,8 +8,8 @@ import (
"testing"
"time"
host
"g
x/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS
/go-libp2p/p2p/host"
netutil
"g
x/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS
/go-libp2p/p2p/test/util"
host
"g
ithub.com/libp2p
/go-libp2p/p2p/host"
netutil
"g
ithub.com/libp2p
/go-libp2p/p2p/test/util"
)
func
getNetHosts
(
t
*
testing
.
T
,
n
int
)
[]
host
.
Host
{
...
...
@@ -94,6 +94,4 @@ func TestBasicFloodsub(t *testing.T) {
}
}
}
fmt
.
Println
(
"Total Sent Messages: "
,
messageCount
)
}
notify.go
View file @
c0d5b0ef
...
...
@@ -3,8 +3,8 @@ package floodsub
import
(
"context"
ma
"g
x/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd
/go-multiaddr"
inet
"g
x/ipfs/Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS
/go-libp2p/p2p/net"
ma
"g
ithub.com/jbenet
/go-multiaddr"
inet
"g
ithub.com/libp2p
/go-libp2p/p2p/net"
)
var
_
inet
.
Notifiee
=
(
*
PubSub
)(
nil
)
...
...
package.json
View file @
c0d5b0ef
...
...
@@ -12,11 +12,17 @@
"hash"
:
"Qmf4ETeAWXuThBfWwonVyFqGFSgTWepUDEr1txcctvpTXS"
,
"name"
:
"go-libp2p"
,
"version"
:
"3.4.1"
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV"
,
"name"
:
"gogo-protobuf"
,
"version"
:
"0.0.0"
}
],
"gxVersion"
:
"0.9.0"
,
"language"
:
"go"
,
"license"
:
""
,
"name"
:
"floodsub"
,
"version"
:
"0.
1
.0"
"version"
:
"0.
2
.0"
}
pb/rpc.pb.go
View file @
c0d5b0ef
...
...
@@ -23,12 +23,6 @@ var _ = proto.Marshal
var
_
=
fmt
.
Errorf
var
_
=
math
.
Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const
_
=
proto
.
GoGoProtoPackageIsVersion2
// please upgrade the proto package
type
RPC
struct
{
Type
*
string
`protobuf:"bytes,1,opt,name=type" json:"type,omitempty"`
Topics
[]
string
`protobuf:"bytes,2,rep,name=topics" json:"topics,omitempty"`
...
...
@@ -36,10 +30,9 @@ type RPC struct {
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
RPC
)
Reset
()
{
*
m
=
RPC
{}
}
func
(
m
*
RPC
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
RPC
)
ProtoMessage
()
{}
func
(
*
RPC
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptorRpc
,
[]
int
{
0
}
}
func
(
m
*
RPC
)
Reset
()
{
*
m
=
RPC
{}
}
func
(
m
*
RPC
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
RPC
)
ProtoMessage
()
{}
func
(
m
*
RPC
)
GetType
()
string
{
if
m
!=
nil
&&
m
.
Type
!=
nil
{
...
...
@@ -70,10 +63,9 @@ type Message struct {
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
Message
)
Reset
()
{
*
m
=
Message
{}
}
func
(
m
*
Message
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
Message
)
ProtoMessage
()
{}
func
(
*
Message
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptorRpc
,
[]
int
{
1
}
}
func
(
m
*
Message
)
Reset
()
{
*
m
=
Message
{}
}
func
(
m
*
Message
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
Message
)
ProtoMessage
()
{}
func
(
m
*
Message
)
GetFrom
()
string
{
if
m
!=
nil
&&
m
.
From
!=
nil
{
...
...
@@ -107,19 +99,3 @@ func init() {
proto
.
RegisterType
((
*
RPC
)(
nil
),
"floodsub.pb.RPC"
)
proto
.
RegisterType
((
*
Message
)(
nil
),
"floodsub.pb.Message"
)
}
func
init
()
{
proto
.
RegisterFile
(
"rpc.proto"
,
fileDescriptorRpc
)
}
var
fileDescriptorRpc
=
[]
byte
{
// 158 bytes of a gzipped FileDescriptorProto
0x1f
,
0x8b
,
0x08
,
0x00
,
0x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ported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment