forked from whyrusleeping/go-smux-multiplex
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move mplex implementation out of go-libp2p, release v0.9.0 (#38)
- Loading branch information
Showing
8 changed files
with
288 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,11 @@ | ||
# DEPRECATION NOTICE | ||
|
||
This package has moved into go-libp2p as a sub-package, github.com/libp2p/go-libp2p/p2p/muxer/mplex. | ||
mplex has been deprecated. | ||
|
||
see https://github.com/libp2p/specs/issues/553 for details | ||
|
||
# go-libp2p-mplex - a go-stream-muxer shim for multiplex | ||
|
||
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) [![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) ![](https://raw.githubusercontent.com/libp2p/go-stream-muxer/master/img/badge.png) | ||
|
||
This is an implementation of the [go-stream-muxer](https://github.com/libp2p/go-stream-muxer) interface for [multiplex](https://github.com/libp2p/go-mplex). For more information, see that repo. | ||
|
||
## Installation | ||
|
||
```sh | ||
go get -d github.com/libp2p/go-libp2p-mplex | ||
cd $GOPATH/src/github.com/libp2p/go-libp2p-mplex | ||
make deps | ||
``` | ||
This is an implementation of the [go-libp2p muxer](https://pkg.go.dev/github.com/libp2p/[email protected]/core/network#Multiplexer) interface for [multiplex](https://github.com/libp2p/go-mplex). For more information, see that repo. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package mplex | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/libp2p/go-libp2p/core/network" | ||
|
||
mp "github.com/libp2p/go-mplex" | ||
) | ||
|
||
type conn mp.Multiplex | ||
|
||
var _ network.MuxedConn = &conn{} | ||
|
||
// NewMuxedConn constructs a new Conn from a *mp.Multiplex. | ||
func NewMuxedConn(m *mp.Multiplex) network.MuxedConn { | ||
return (*conn)(m) | ||
} | ||
|
||
func (c *conn) Close() error { | ||
return c.mplex().Close() | ||
} | ||
|
||
func (c *conn) IsClosed() bool { | ||
return c.mplex().IsClosed() | ||
} | ||
|
||
// OpenStream creates a new stream. | ||
func (c *conn) OpenStream(ctx context.Context) (network.MuxedStream, error) { | ||
s, err := c.mplex().NewStream(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return (*stream)(s), nil | ||
} | ||
|
||
// AcceptStream accepts a stream opened by the other side. | ||
func (c *conn) AcceptStream() (network.MuxedStream, error) { | ||
s, err := c.mplex().Accept() | ||
if err != nil { | ||
return nil, err | ||
} | ||
return (*stream)(s), nil | ||
} | ||
|
||
func (c *conn) mplex() *mp.Multiplex { | ||
return (*mp.Multiplex)(c) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.