<commit_before>// Copyright © 2015 The Things Network
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.

package gtw_rtr_moke

import (
	"github.com/thethingsnetwork/core"
	"github.com/thethingsnetwork/core/lorawan/semtech"
)

type Adapter struct{}

// New constructs a new Gateway-Router-Moke adapter
func New(router core.Router, port uint) (*Adapter, error) {
	return nil, nil
}

// Ack implements the core.GatewayRouterAdapter interface
func (a *Adapter) Connect(router core.Router, port uint) error {
	return nil
}

// Ack implements the core.GatewayRouterAdapter interface
func (a *Adapter) Ack(router core.Router, packet semtech.Packet, gateway core.GatewayAddress) {
}<commit_msg>[router] Implements basic mock upadapter<commit_after>// Copyright © 2015 The Things Network
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.

// package gtw_rtr_moke offers a gateway <-> router moke adapter that can be used to test a router
// implementation.
package gtw_rtr_moke

import (
	"fmt"
	"github.com/thethingsnetwork/core"
	"github.com/thethingsnetwork/core/lorawan/semtech"
)

type Adapter struct {
	FailAck     bool
	FailConnect bool
	connected   bool
	acks        map[core.GatewayAddress][]semtech.Packet
}

// New constructs a new Gateway-Router-Moke adapter
func New() (*Adapter, error) {
	return &Adapter{
		FailAck:     false,
		FailConnect: false,
		connected:   false,
		acks:        make(map[core.GatewayAddress][]semtech.Packet),
	}, nil
}

// Listen implements the core.Adapter interface
func (a *Adapter) Listen(router core.Router, options interface{}) error {
	if a.FailConnect {
		return fmt.Errorf("Unable to establish connection")
	}
	a.connected = true
	return nil
}

// Ack implements the core.GatewayRouterAdapter interface
func (a *Adapter) Ack(router core.Router, packet semtech.Packet, gateway core.GatewayAddress) {
	if a.FailAck {
		router.HandleError(core.ErrAck(fmt.Errorf("Unable to ack the given packet")))
		return
	}
	a.acks[gateway] = append(a.acks[gateway], packet)
}

func (a *Adapter) GetAcks(gateway core.GatewayAddress) []semtech.Packet {
	return a.acks[gateway]
}
{'fraction_non_alphanumeric': 0.09977220956719818, 'fraction_numerical': 0.0036446469248291574, 'mean_word_length': 4.35609756097561, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4926353', 'n_tokens_mistral': 702, 'n_tokens_neox': 681, 'n_words': 222}