mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-29 14:45:07 +03:00
Added two new methods
In order to implement https://github.com/yggdrasil-network/yggdrasil-android/issues/25 we need these new methods.
This commit is contained in:
parent
cfa293d189
commit
3a61727348
1 changed files with 22 additions and 0 deletions
|
@ -115,6 +115,18 @@ func (m *Yggdrasil) Send(p []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send sends a packet to Yggdrasil. It should be a fully formed IPv6 packet
|
||||||
|
func (m *Yggdrasil) SendBytes(p []byte, length int) error {
|
||||||
|
if m.iprwc == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if len(p) < length {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
_, _ = m.iprwc.Write(p[:length])
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Recv waits for and reads a packet coming from Yggdrasil. It
|
// Recv waits for and reads a packet coming from Yggdrasil. It
|
||||||
// will be a fully formed IPv6 packet
|
// will be a fully formed IPv6 packet
|
||||||
func (m *Yggdrasil) Recv() ([]byte, error) {
|
func (m *Yggdrasil) Recv() ([]byte, error) {
|
||||||
|
@ -126,6 +138,16 @@ func (m *Yggdrasil) Recv() ([]byte, error) {
|
||||||
return buf[:n], nil
|
return buf[:n], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Recv waits for and reads a packet coming from Yggdrasil to given buffer, returning length of it
|
||||||
|
// It will be a fully formed IPv6 packet
|
||||||
|
func (m *Yggdrasil) RecvBytes(buf []byte) (int, error) {
|
||||||
|
if m.iprwc == nil {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
n, _ := m.iprwc.Read(buf)
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Stop the mobile Yggdrasil instance
|
// Stop the mobile Yggdrasil instance
|
||||||
func (m *Yggdrasil) Stop() error {
|
func (m *Yggdrasil) Stop() error {
|
||||||
logger := log.New(m.log, "", 0)
|
logger := log.New(m.log, "", 0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue