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
dms3
go-unixfs
Commits
4b06adf7
Commit
4b06adf7
authored
10 years ago
by
Carlos Cobo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gofmt
parent
7d6a5830
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
96 deletions
+96
-96
bitswap/bitswap.go
bitswap/bitswap.go
+6
-6
netmux/interface.go
netmux/interface.go
+66
-66
netmux/netmux.go
netmux/netmux.go
+24
-24
No files found.
bitswap/bitswap.go
View file @
4b06adf7
package
bitswap
import
(
"github.com/jbenet/go-ipfs/blocks"
"github.com/jbenet/go-multihash"
"github.com/jbenet/go-ipfs/blocks"
"github.com/jbenet/go-multihash"
)
// aliases
type
Ledger
struct
{
// todo
// todo
}
type
BitSwap
struct
{
Ledgers
map
[
string
]
*
Ledger
HaveList
map
[
string
]
*
blocks
.
Block
WantList
[]
*
multihash
.
Multihash
Ledgers
map
[
string
]
*
Ledger
HaveList
map
[
string
]
*
blocks
.
Block
WantList
[]
*
multihash
.
Multihash
}
This diff is collapsed.
Click to expand it.
netmux/interface.go
View file @
4b06adf7
package
netmux
import
(
"net"
"net"
)
// An interface is the module connecting netmux
...
...
@@ -9,88 +9,88 @@ import (
// It keeps the relevant connections open.
type
Interface
struct
{
// Interface network (e.g. udp4, tcp6)
Network
string
// Interface network (e.g. udp4, tcp6)
Network
string
// Own network address
Address
string
ResolvedAddress
*
net
.
UDPAddr
// Own network address
Address
string
ResolvedAddress
*
net
.
UDPAddr
// Connection
conn
net
.
Conn
// Connection
conn
net
.
Conn
// next packets + close control channels
Input
chan
*
Packet
Output
chan
*
Packet
Closed
chan
bool
Errors
chan
error
// next packets + close control channels
Input
chan
*
Packet
Output
chan
*
Packet
Closed
chan
bool
Errors
chan
error
}
func
NewUDPInterface
(
network
,
addr
string
)
(
*
Interface
,
error
)
{
raddr
,
err
:=
net
.
ResolveUDPAddr
(
network
,
addr
)
if
err
!=
nil
{
return
nil
,
err
}
conn
,
err
:=
net
.
ListenUDP
(
network
,
raddr
)
if
err
!=
nil
{
return
nil
,
err
}
i
:=
&
Interface
{
Network
:
network
,
Address
:
addr
,
ResolvedAddress
:
raddr
,
conn
:
conn
,
}
go
i
.
processUDPInput
()
go
i
.
processOutput
()
return
i
,
nil
raddr
,
err
:=
net
.
ResolveUDPAddr
(
network
,
addr
)
if
err
!=
nil
{
return
nil
,
err
}
conn
,
err
:=
net
.
ListenUDP
(
network
,
raddr
)
if
err
!=
nil
{
return
nil
,
err
}
i
:=
&
Interface
{
Network
:
network
,
Address
:
addr
,
ResolvedAddress
:
raddr
,
conn
:
conn
,
}
go
i
.
processUDPInput
()
go
i
.
processOutput
()
return
i
,
nil
}
func
(
i
*
Interface
)
processOutput
()
{
for
{
select
{
case
<-
i
.
Closed
:
break
case
buffer
:=
<-
i
.
Output
:
i
.
conn
.
Write
([]
byte
(
buffer
.
Data
))
}
}
for
{
select
{
case
<-
i
.
Closed
:
break
case
buffer
:=
<-
i
.
Output
:
i
.
conn
.
Write
([]
byte
(
buffer
.
Data
))
}
}
}
func
(
i
*
Interface
)
processUDPInput
()
{
for
{
select
{
case
<-
i
.
Closed
:
break
for
{
select
{
case
<-
i
.
Closed
:
break
}
}
}
}
}
func
(
i
*
Interface
)
Read
(
buffer
[]
byte
)
bool
{
_
,
err
:=
i
.
conn
.
Read
(
buffer
)
if
err
!=
nil
{
i
.
Errors
<-
err
i
.
Close
()
return
false
}
return
true
_
,
err
:=
i
.
conn
.
Read
(
buffer
)
if
err
!=
nil
{
i
.
Errors
<-
err
i
.
Close
()
return
false
}
return
true
}
func
(
i
*
Interface
)
Close
()
{
// closing net connection
err
:=
i
.
conn
.
Close
()
if
err
!=
nil
{
i
.
Errors
<-
err
}
// closing channels
close
(
i
.
Input
)
close
(
i
.
Output
)
close
(
i
.
Closed
)
close
(
i
.
Errors
)
// closing net connection
err
:=
i
.
conn
.
Close
()
if
err
!=
nil
{
i
.
Errors
<-
err
}
// closing channels
close
(
i
.
Input
)
close
(
i
.
Output
)
close
(
i
.
Closed
)
close
(
i
.
Errors
)
}
This diff is collapsed.
Click to expand it.
netmux/netmux.go
View file @
4b06adf7
...
...
@@ -6,41 +6,41 @@ package netmux
// and multiplex everything over one interface.
type
Netmux
struct
{
// the list of NetMux interfaces
Interfaces
[]
*
Interface
// the list of NetMux interfaces
Interfaces
[]
*
Interface
// The channels to send/recv from
Incoming
<-
chan
*
Packet
Outgoing
chan
<-
*
Packet
// The channels to send/recv from
Incoming
<-
chan
*
Packet
Outgoing
chan
<-
*
Packet
// internally managed other side of channels
incomingSrc
chan
<-
*
Packet
outgoingSrc
<-
chan
*
Packet
// internally managed other side of channels
incomingSrc
chan
<-
*
Packet
outgoingSrc
<-
chan
*
Packet
}
// Warning: will probably change to adopt multiaddr format
type
Packet
struct
{
// the network addresses to send to
// e.g. tcp4://127.0.0.1:12345
NetAddrTo
string
// the network addresses to send to
// e.g. tcp4://127.0.0.1:12345
NetAddrTo
string
// the network addresses to recv from
// e.g. tcp4://127.0.0.1:12345
// may be left blank to select one automatically.
NetAddrFrom
string
// the network addresses to recv from
// e.g. tcp4://127.0.0.1:12345
// may be left blank to select one automatically.
NetAddrFrom
string
// the data to send.
Data
[]
byte
// the data to send.
Data
[]
byte
}
func
NewNetmux
()
*
Netmux
{
n
:=
&
Netmux
{}
n
:=
&
Netmux
{}
// setup channels
och
:=
make
(
chan
*
Packet
)
ich
:=
make
(
chan
*
Packet
)
n
.
Incoming
,
n
.
incomingSrc
=
ich
,
ich
n
.
Outgoing
,
n
.
outgoingSrc
=
och
,
och
// setup channels
och
:=
make
(
chan
*
Packet
)
ich
:=
make
(
chan
*
Packet
)
n
.
Incoming
,
n
.
incomingSrc
=
ich
,
ich
n
.
Outgoing
,
n
.
outgoingSrc
=
och
,
och
return
n
return
n
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
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