Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
qqqeck committed Jun 25, 2024
1 parent bbb67b8 commit b87a6c5
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions p2p/host/basic/basic_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -1146,10 +1146,12 @@ type streamWrapper struct {
}

func (s *streamWrapper) Read(b []byte) (int, error) {
fmt.Println("host/basic/basic_host.go:read")
return s.rw.Read(b)
}

func (s *streamWrapper) Write(b []byte) (int, error) {
fmt.Println("host/basic/basic_host.go")
return s.rw.Write(b)
}

Expand Down
3 changes: 3 additions & 0 deletions p2p/muxer/mplex/stream.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mplex

import (
"fmt"
"time"

"github.com/libp2p/go-libp2p/core/network"
Expand All @@ -14,6 +15,7 @@ type stream mp.Stream
var _ network.MuxedStream = &stream{}

func (s *stream) Read(b []byte) (n int, err error) {
fmt.Println("mplex/stream.go:read")
n, err = s.mplex().Read(b)
if err == mp.ErrStreamReset {
err = network.ErrReset
Expand All @@ -23,6 +25,7 @@ func (s *stream) Read(b []byte) (n int, err error) {
}

func (s *stream) Write(b []byte) (n int, err error) {
fmt.Println("mplex/stream.go")
n, err = s.mplex().Write(b)
if err == mp.ErrStreamReset {
err = network.ErrReset
Expand Down
3 changes: 3 additions & 0 deletions p2p/muxer/yamux/stream.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package yamux

import (
"fmt"
"time"

"github.com/libp2p/go-libp2p/core/network"
Expand All @@ -14,6 +15,7 @@ type stream yamux.Stream
var _ network.MuxedStream = &stream{}

func (s *stream) Read(b []byte) (n int, err error) {
fmt.Println("yamux/stream.go:read")
n, err = s.yamux().Read(b)
if err == yamux.ErrStreamReset {
err = network.ErrReset
Expand All @@ -23,6 +25,7 @@ func (s *stream) Read(b []byte) (n int, err error) {
}

func (s *stream) Write(b []byte) (n int, err error) {
fmt.Println("yamux/stream.go")
n, err = s.yamux().Write(b)
if err == yamux.ErrStreamReset {
err = network.ErrReset
Expand Down
3 changes: 3 additions & 0 deletions p2p/net/pnet/psk_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pnet
import (
"crypto/cipher"
"crypto/rand"
"fmt"
"io"
"net"

Expand All @@ -29,6 +30,7 @@ type pskConn struct {
}

func (c *pskConn) Read(out []byte) (int, error) {
fmt.Println("pnet/psk_conn.go:read")
if c.readS20 == nil {
nonce := make([]byte, 24)
_, err := io.ReadFull(c.Conn, nonce)
Expand All @@ -46,6 +48,7 @@ func (c *pskConn) Read(out []byte) (int, error) {
}

func (c *pskConn) Write(in []byte) (int, error) {
fmt.Println("pnet/psk_conn.go")
if c.writeS20 == nil {
nonce := make([]byte, 24)
_, err := rand.Read(nonce)
Expand Down
2 changes: 2 additions & 0 deletions p2p/net/swarm/swarm_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (s *Stream) Conn() network.Conn {

// Read reads bytes from a stream.
func (s *Stream) Read(p []byte) (int, error) {
fmt.Println("swarm/read")
n, err := s.stream.Read(p)
// TODO: push this down to a lower level for better accuracy.
if s.conn.swarm.bwc != nil {
Expand All @@ -63,6 +64,7 @@ func (s *Stream) Read(p []byte) (int, error) {

// Write writes bytes to a stream, flushing for each call.
func (s *Stream) Write(p []byte) (int, error) {
fmt.Println("swarm_steam.go: Write")
n, err := s.stream.Write(p)
// TODO: push this down to a lower level for better accuracy.
if s.conn.swarm.bwc != nil {
Expand Down
2 changes: 2 additions & 0 deletions p2p/protocol/circuitv2/client/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ func (c *Conn) Close() error {
}

func (c *Conn) Read(buf []byte) (int, error) {
fmt.Println("circuitv2/read")
return c.stream.Read(buf)
}

func (c *Conn) Write(buf []byte) (int, error) {
fmt.Println("circuitv2/client/conn.go: Write")
return c.stream.Write(buf)
}

Expand Down
3 changes: 3 additions & 0 deletions p2p/security/noise/rw.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package noise

import (
"encoding/binary"
"fmt"
"io"

pool "github.com/libp2p/go-buffer-pool"
Expand All @@ -24,6 +25,7 @@ const LengthPrefixLength = 2
//
// Honours io.Reader in terms of behaviour.
func (s *secureSession) Read(buf []byte) (int, error) {
fmt.Println("security/noise:read")
s.readLock.Lock()
defer s.readLock.Unlock()

Expand Down Expand Up @@ -89,6 +91,7 @@ func (s *secureSession) Read(buf []byte) (int, error) {
// Write encrypts the plaintext `in` data and sends it on the
// secure connection.
func (s *secureSession) Write(data []byte) (int, error) {
fmt.Println("noise/rw.go: Write")
s.writeLock.Lock()
defer s.writeLock.Unlock()

Expand Down
3 changes: 3 additions & 0 deletions p2p/transport/quic/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package libp2pquic

import (
"errors"
"fmt"

"github.com/libp2p/go-libp2p/core/network"

Expand All @@ -19,6 +20,7 @@ type stream struct {
var _ network.MuxedStream = &stream{}

func (s *stream) Read(b []byte) (n int, err error) {
fmt.Println("quic/strea:read")
n, err = s.Stream.Read(b)
if err != nil && errors.Is(err, &quic.StreamError{}) {
err = network.ErrReset
Expand All @@ -27,6 +29,7 @@ func (s *stream) Read(b []byte) (n int, err error) {
}

func (s *stream) Write(b []byte) (n int, err error) {
fmt.Println("quic/stream.go")
n, err = s.Stream.Write(b)
if err != nil && errors.Is(err, &quic.StreamError{}) {
err = network.ErrReset
Expand Down
2 changes: 2 additions & 0 deletions p2p/transport/websocket/conn.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package websocket

import (
"fmt"
"net"

"github.com/libp2p/go-libp2p/core/network"
Expand All @@ -27,6 +28,7 @@ func (c conn) RemoteAddr() net.Addr {
}

func (c conn) Read(b []byte) (int, error) {
fmt.Println("websocket/conn.go:read")
n, err := c.Conn.Read(b)
if err == nil && n == 0 && c.readAttempts < maxReadAttempts {
c.readAttempts++
Expand Down
1 change: 1 addition & 0 deletions p2p/transport/webtransport/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ func newDeterministicReader(seed []byte, salt []byte, info string) io.Reader {
}

func (r *deterministicReader) Read(p []byte) (n int, err error) {
fmt.Println("webtransport/crypto.go:read")
if len(p) == 1 {
return r.singleByteReader.Read(p)
}
Expand Down
3 changes: 3 additions & 0 deletions p2p/transport/webtransport/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package libp2pwebtransport

import (
"errors"
"fmt"
"net"

"github.com/libp2p/go-libp2p/core/network"
Expand Down Expand Up @@ -35,6 +36,7 @@ type stream struct {
var _ network.MuxedStream = &stream{}

func (s *stream) Read(b []byte) (n int, err error) {
fmt.Println("webtrasnplort/stream.go:read")
n, err = s.Stream.Read(b)
if err != nil && errors.Is(err, &webtransport.StreamError{}) {
err = network.ErrReset
Expand All @@ -43,6 +45,7 @@ func (s *stream) Read(b []byte) (n int, err error) {
}

func (s *stream) Write(b []byte) (n int, err error) {
fmt.Println("webtransport/stream.go")
n, err = s.Stream.Write(b)
if err != nil && errors.Is(err, &webtransport.StreamError{}) {
err = network.ErrReset
Expand Down

0 comments on commit b87a6c5

Please sign in to comment.