-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sorin Dumitru <[email protected]>
- Loading branch information
1 parent
f1b4001
commit e9ea66d
Showing
3 changed files
with
64 additions
and
47 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,54 +1,37 @@ | ||
package peertracker | ||
|
||
import "net" | ||
import "fmt" | ||
import "github.com/mdlayher/vsock" | ||
import ( | ||
"github.com/mdlayher/vsock" | ||
) | ||
|
||
func (lf *ListenerFactory) ListenVSock(port uint32) (*Listener, error) { | ||
if lf.NewUnixListener == nil { | ||
lf.NewVSockListener = vsock.Listen | ||
} | ||
if lf.NewTracker == nil { | ||
lf.NewTracker = NewTracker | ||
} | ||
if lf.Log == nil { | ||
lf.Log = newNoopLogger() | ||
} | ||
return lf.listenVSock(port) | ||
if lf.NewUnixListener == nil { | ||
lf.NewVSockListener = vsock.Listen | ||
} | ||
if lf.NewTracker == nil { | ||
lf.NewTracker = NewTracker | ||
} | ||
if lf.Log == nil { | ||
lf.Log = newNoopLogger() | ||
} | ||
return lf.listenVSock(port) | ||
} | ||
|
||
func (lf *ListenerFactory) listenVSock(port uint32) (*Listener, error) { | ||
l, err := lf.NewVSockListener(port, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
tracker, err := lf.NewTracker(lf.Log) | ||
if err != nil { | ||
l.Close() | ||
return nil, err | ||
} | ||
|
||
return &Listener{ | ||
l: l, | ||
Tracker: tracker, | ||
log: lf.Log, | ||
}, nil | ||
} | ||
l, err := lf.NewVSockListener(port, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
func CallerFromVSockConn(conn net.Conn) (CallerInfo, error) { | ||
var info CallerInfo | ||
cid := int(conn.RemoteAddr().(*vsock.Addr).ContextID) | ||
pid := CID2PID(cid) | ||
fmt.Printf("Got PID %d for CID %d\n", pid, cid) | ||
if pid < 0 { | ||
return info, fmt.Errorf("Could not fetch PID from CID") | ||
tracker, err := lf.NewTracker(lf.Log) | ||
if err != nil { | ||
l.Close() | ||
return nil, err | ||
} | ||
info = CallerInfo{ | ||
PID: int32(pid), | ||
} | ||
|
||
info.Addr = conn.RemoteAddr() | ||
return info, nil | ||
return &Listener{ | ||
l: l, | ||
Tracker: tracker, | ||
log: lf.Log, | ||
}, nil | ||
} | ||
|
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
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,13 @@ | ||
//go:build !linux | ||
// +build !linux | ||
|
||
package peertracker | ||
|
||
import ( | ||
"errors" | ||
"net" | ||
) | ||
|
||
func CallerFromVSockConn(conn net.Conn) (CallerInfo, error) { | ||
return CallerInfo{}, errors.New("not supported") | ||
} |