package iroh
import (
"context"
"github.com/tmc/go-iroh/internal/socket"
"github.com/tmc/go-iroh/netaddr"
)
type CustomDatagram struct {
Remote netaddr .CustomAddr
Local netaddr .CustomAddr
HasLocal bool
Data []byte
}
type CustomTransport interface {
Serve (ctx context .Context , recv func (CustomDatagram ) bool )
Send (remote netaddr .CustomAddr , local *netaddr .CustomAddr , p []byte ) bool
}
type AdvertisingCustomTransport interface {
CustomTransport
LocalCustomAddrs (context .Context ) ([]netaddr .CustomAddr , error )
}
type customTransportAdapter struct {
t CustomTransport
}
func (a customTransportAdapter ) Serve (ctx context .Context , recv func (socket .CustomDatagram ) bool ) {
a .t .Serve (ctx , func (d CustomDatagram ) bool {
return recv (socket .CustomDatagram {
Remote : d .Remote ,
Local : d .Local ,
HasLocal : d .HasLocal ,
Data : d .Data ,
})
})
}
func (a customTransportAdapter ) Send (remote netaddr .CustomAddr , local *netaddr .CustomAddr , p []byte ) bool {
return a .t .Send (remote , local , p )
}
func customTransportAdapters(custom []CustomTransport ) []socket .CustomTransport {
if len (custom ) == 0 {
return nil
}
out := make ([]socket .CustomTransport , 0 , len (custom ))
for _ , t := range custom {
if t != nil {
out = append (out , customTransportAdapter {t : t })
}
}
return out
}
func customTransportLocalAddrs(ctx context .Context , custom []CustomTransport ) []netaddr .CustomAddr {
var out []netaddr .CustomAddr
for _ , t := range custom {
a , ok := t .(AdvertisingCustomTransport )
if !ok {
continue
}
addrs , err := a .LocalCustomAddrs (ctx )
if err != nil {
continue
}
out = append (out , addrs ...)
}
return out
}
The pages are generated with Golds v0.8.4 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .