After months of emergency rule and military operations in Nigeria's north-east, a few weeks ago Boko Haram launched a comprehensive and audacious assault on Maiduguri, the capital of Borno state.
In a multi-pronged attack, hundreds of insurgents reportedly targeted the city's military barracks, Maiduguri University, and an area where civil servants are known to live.
In its temerity and scale the attack is reminiscent of the Taliban's notorious 2012 assault on Kabul. It proves what many of us already suspected - that the state of emergency imposed last spring and the deployment of thousands of troops since then have done nothing to weaken Boko Haram. They are alive and well.
This attack has been in the making for a few weeks. More than 1,300 people have been killed in the last two months as the insurgents have ramped up the violence.
They've been daring and brutal, attacking villages all around Maiduguri. Most often the military are not there to protect people. When they are there, they often run away. And it routinely takes them hours to respond to any attack in full force.
But the problem isn't just the military's fighting performance. The security forces are accused of arbitrarily rounding up young men on the streets and shooting them. Amnesty International has long accused the security forces of burning homes and carrying out summary executions in response to attacks.
Their most recent report claimed police are presiding over hundreds of deaths in detention. These tactics are entirely counter-productive.
They strengthen the insurgency by alienating people and pushing them into the hands of Boko Haram - as sympathisers and recruits. In fact, if this conduct is routine, it is very possible that the extra troop deployments have made things worse rather than better.
How can Nigeria turn this around? There needs to be nothing short of a revolution in strategy and capabilities.
Improving capabilities should firstly be about training. It is quite clear that the army is not properly trained to carry out a counter-insurgency campaign.
They are still being trained as if they were fighting a conventional war. But 95 percent of the time counter-insurgency doesn't involve shooting at anyone. It involves denying insurgents space and support by providing reliable security and winning the confidence of local people. No soldiers should be sent north unless they know how to do this.
It's also about numbers. Counter-insurgencies require large numbers of troops because, unlike the insurgents, you have to hold territory and protect the population.
Nigeria should try and recruit some of the extra troops from the north, specifically from the Kanuri ethnic group where the insurgency is said to have most of its support. Kanuri soldiers will be more trusted by the local population and will be less likely to commit human rights violations. The downside is the risk of infiltration.
The army will have to understand the importance of vetting from the very beginning, and should work through trusted local leaders to recruit. Elsewhere, they should try and recruit more from groups with whom the Kanuri have not historically had poor relations.
To boost both skills and numbers, Nigeria is going to need outside help. They will need Western advisors to help train the troops in counter-insurgency tactics, and they will probably need Western funding too. European countries and the USA should start thinking about a counter-terrorism assistance package.
The problem is they will rightly be concerned about supporting an army that has been accused of so many human rights violations. That's why they should insist on accountability for human rights violations. And they should also ensure that the training instils the need to respect human rights and protect the population right through the ranks.
Most critically, the strategy must change. Insurgents are only able to succeed when they have some support amongst the local population.
Since they do not have the capacity to win a conventional war involving constant battles out in the open, they must be able to hide themselves and their equipment from the army in between surprise attacks. They must also recruit people into their ranks. Both of these require some level of local support. Boko Haram certainly has this, as the New York Times has reported.
The only way to defeat an insurgency is to drain it of this support. The battle, then, is primarily political rather than military. Put simply, you've got to make a better offer to the people than the insurgents can. You've got to encourage them to turn the insurgents in rather than shelter and join them.
How do you do this? The first step is to understand. Who are Boko Haram? Who might be sympathetic to them and why? How much support do they have and from which particular areas and villages? These questions need answers. There is an impressive amount of data out there about what Afghans think, for example, about the Taliban, NATO forces, and the Afghan government.
There has also been a lot of effort put into identifying exactly who the Taliban are - where they come from and what they want. Naturally, a complex picture emerges of an insurgency with various different elements and motivations, and supporters with varying levels of sympathy and reasons for sympathising.
There is undoubtedly a similar picture in north-east Nigeria waiting to be discovered, documented, and used for counter-insurgency purposes.
The second step is knowing what not to do. In general, heavy-handed tactics and human rights violations make things worse because they alienate civilians and increase sympathy for the enemy. Corruption is also highly alienating. These should be obvious points, but little progress seems to have been made on either front.
The government should start by adopting a zero tolerance policy on both, and announcing prosecutions for past crimes.
The Nigerian courts do not have the capacity to put every human rights violator or corrupt official on trial, so they'll have to hope that a few high-profile, well publicised prosecutions are sufficient as a deterrent.
All security forces should be given anti-corruption training, as well as human rights training. They should also be trained to avoid methods of fighting that are likely to accidentally kill civilians.
Finally you've got to know what proactive actions to take. Most importantly, you must provide security. Insecurity will undermine confidence in the state and encourage people to look for alternative sources of authority and protection.
The number one focus of the counter-insurgency effort should be to protect the population. This is far more important than pro-actively searching for insurgents and killing them, which can even be counter-productive.
On a tactical level, it makes more sense to deploy small numbers of troops into different villages than to keep them all inside bases. They will be more able to respond to attacks and protect the population.
You may think these troops would invite attacks on themselves and the villages they inhabit, but experience in Afghanistan counter-intuitively suggests attacks on small groups are actually much less likely than attacks on large bases.
Smaller groups of soldiers deployed in villages will be able to develop relationships with villagers, gather intelligence, and deny the insurgents military and political space. This will be vital in defeating the insurgency.
But it shouldn't be done unless the troops are well trained. If and when they are attacked, they'll be far away from help. They're also more likely to commit human rights violations if they're living with villagers. So the soldiers that do this will have to be better at fighting and more respectful of the population than average troops.
In Afghanistan, NATO soldiers were specially trained for 'village stability operations'. These were very effective in improving security, as demonstrated by several case studies. Nigeria should consider creating a special force for similar operations.
It's also a good idea to work with local people. They will be trusted more by civilians and are less likely to commit human rights violations. Borno state's civilian JTF initiative, championed by Governor Shettima, is a good model that could be rolled out across the three embattled states.
The potential pitfalls are that paramilitaries may be more interested in using weapons to settle local disputes than to protect people from Boko Haram, and that they may attract more attacks on the civilian population. Alarmingly, there have been reports of Boko Haram killing civilians after accusing them of being in the civilian JTF.
The way to get round the first problem is to ensure local dynamics are fully understood before equipping a paramilitary force. If it seems likely they will use their weapons to simply attack another village, it's best to avoid arming them.
It will also be important to train them and ensure they are accountable both to the state and to the communities they serve. Indeed, Governor Shettima has gone to great lengths to train the civilian JTF.
As for whether they invite attacks on civilians, the government will have to make a judgement as to whether this risk is outweighed by the benefits. I would argue it is, especially as the civilian JTF are credited with pushing Boko Haram out of Maiduguri last year - something the army were unable to achieve.
Economic development is also key. Governor Shettima has spoken of the need for a 'Marshall Plan' for the north. It is desperately needed. In the north of the country, 72% of people live in poverty, compared with 27% in the south.
Poverty and lack of opportunities make it easy for Boko Haram to attract recruits and sympathisers. The government should also provide better services for local people. Insurgencies thrive when they are able to step in as service providers, which is what Boko Haram originally did.
Development will not be a quick fix. We are talking about a generational change. But it is vital that Nigeria starts now. Western governments and institutions should step in to help.
This includes the World Bank, which is now focusing on conflict affected states. But a return to insisting on structural adjustment, which limits the government's role as a service provider, would be unwise.
Another ingredient is the narrative. A successful counter-insurgency must create favourable political dividing lines between government forces and the insurgents.
In theory, Boko Haram does not make it difficult to do this. They primarily kill Muslim civilians and are responsible for disorder and violence.
The government has the opportunity to portray itself as a champion of security and development. But as long as troops continue to be ineffective and commit human rights violations, and as long as the poverty rate remains high, this will be difficult.
Nigeria can win this war, but they need to start turning it around now. The north needs economic development on a massive scale; it needs well-trained troops working with reliable local volunteers, and a visible security presence even in remote areas.
And all of this needs to be packaged into a convincing narrative that can deliver that vital political victory. Without this, we can only expect things to get worse.
Andrew Noakes is a human rights activist and freelance journalist covering Africa.